Skip to content

Commit 2c9998a

Browse files
committed
add CPU metrics fallback for non-Linux systems
1 parent e08a36d commit 2c9998a

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

‎src/handlers/http/resource_check.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,11 @@ pub fn cpu_limit_cores() -> f64 {
275275

276276
#[cfg(not(target_os = "linux"))]
277277
{
278-
0.0
278+
num_cpus::get() as f64
279279
}
280280
}
281281

282-
fn cpu_metrics() -> (f64, f64) {
282+
fn cpu_metrics(_cpu_usage_percent: f64) -> (f64, f64) {
283283
#[cfg(target_os = "linux")]
284284
{
285285
match cgroup_cpu_metrics() {
@@ -298,7 +298,7 @@ fn cpu_metrics() -> (f64, f64) {
298298

299299
#[cfg(not(target_os = "linux"))]
300300
{
301-
(0.0, 0.0)
301+
(num_cpus::get() as f64, _cpu_usage_percent / 100.0)
302302
}
303303
}
304304

@@ -319,7 +319,7 @@ async fn sample_process_metrics() {
319319
};
320320

321321
process_metrics.map(|(cpu_usage, memory_bytes, total_mem)| {
322-
let (cpu_limit_cores, cpu_usage_cores) = cpu_metrics();
322+
let (cpu_limit_cores, cpu_usage_cores) = cpu_metrics(cpu_usage);
323323
(
324324
cpu_usage,
325325
memory_bytes,

‎src/metrics/mod.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ pub static PROCESS_CPU_USAGE_CORES: Lazy<Gauge> = Lazy::new(|| {
251251
Gauge::with_opts(
252252
Opts::new(
253253
"process_cpu_usage_cores",
254-
"Average CPU cores used by the Parseable cgroup over the last minute",
254+
"Average CPU cores used by Parseable over the last minute",
255255
)
256256
.namespace(METRICS_NAMESPACE),
257257
)

0 commit comments

Comments
 (0)