From 800e4a9cfbf9d1cec667db50219eaf66a451bd47 Mon Sep 17 00:00:00 2001 From: Yu Li Date: Sat, 26 Mar 2022 17:41:29 +0800 Subject: [PATCH] agent: use ms as unit of cputime instead of ticks For the library `procfs`, the unit of values in `CpuTime` is ticks, and we do not know how many ticks per second from metrics because the `tps` in `CpuTime` is private. But there are some implements in `CpuTime` for getting these values, e.g., `user_ms()` for `user`, and `nice_ms()` for `nice`. With these values, accurate time can be obtained. Fixes: #3979 Acked-by: zhaojizhuang <571130360@qq.com> Signed-off-by: Yu Li --- src/agent/src/metrics.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/agent/src/metrics.rs b/src/agent/src/metrics.rs index 1c75fc22d9..508d7d2c2a 100644 --- a/src/agent/src/metrics.rs +++ b/src/agent/src/metrics.rs @@ -344,25 +344,25 @@ fn set_gauge_vec_meminfo(gv: &prometheus::GaugeVec, meminfo: &procfs::Meminfo) { #[instrument] fn set_gauge_vec_cpu_time(gv: &prometheus::GaugeVec, cpu: &str, cpu_time: &procfs::CpuTime) { gv.with_label_values(&[cpu, "user"]) - .set(cpu_time.user as f64); + .set(cpu_time.user_ms() as f64); gv.with_label_values(&[cpu, "nice"]) - .set(cpu_time.nice as f64); + .set(cpu_time.nice_ms() as f64); gv.with_label_values(&[cpu, "system"]) - .set(cpu_time.system as f64); + .set(cpu_time.system_ms() as f64); gv.with_label_values(&[cpu, "idle"]) - .set(cpu_time.idle as f64); + .set(cpu_time.idle_ms() as f64); gv.with_label_values(&[cpu, "iowait"]) - .set(cpu_time.iowait.unwrap_or(0) as f64); + .set(cpu_time.iowait_ms().unwrap_or(0) as f64); gv.with_label_values(&[cpu, "irq"]) - .set(cpu_time.irq.unwrap_or(0) as f64); + .set(cpu_time.irq_ms().unwrap_or(0) as f64); gv.with_label_values(&[cpu, "softirq"]) - .set(cpu_time.softirq.unwrap_or(0) as f64); + .set(cpu_time.softirq_ms().unwrap_or(0) as f64); gv.with_label_values(&[cpu, "steal"]) - .set(cpu_time.steal.unwrap_or(0) as f64); + .set(cpu_time.steal_ms().unwrap_or(0) as f64); gv.with_label_values(&[cpu, "guest"]) - .set(cpu_time.guest.unwrap_or(0) as f64); + .set(cpu_time.guest_ms().unwrap_or(0) as f64); gv.with_label_values(&[cpu, "guest_nice"]) - .set(cpu_time.guest_nice.unwrap_or(0) as f64); + .set(cpu_time.guest_nice_ms().unwrap_or(0) as f64); } #[instrument]