Skip to content

Commit f82cbe9

Browse files
committed
set process_cpu_seconds_total to type counter
1 parent 2aae08a commit f82cbe9

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

common/health_metrics/src/metrics.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ pub static PROCESS_SHR_MEM: LazyLock<Result<IntGauge>> = LazyLock::new(|| {
2727
"Shared memory used by the current process",
2828
)
2929
});
30-
pub static PROCESS_SECONDS: LazyLock<Result<IntGauge>> = LazyLock::new(|| {
31-
try_create_int_gauge(
30+
pub static PROCESS_SECONDS: LazyLock<Result<IntCounter>> = LazyLock::new(|| {
31+
try_create_int_counter(
3232
"process_cpu_seconds_total",
3333
"Total cpu time taken by the current process",
3434
)
@@ -135,8 +135,13 @@ pub fn scrape_process_health_metrics() {
135135
set_gauge(&PROCESS_RES_MEM, health.pid_mem_resident_set_size as i64);
136136
set_gauge(&PROCESS_VIRT_MEM, health.pid_mem_virtual_memory_size as i64);
137137
set_gauge(&PROCESS_SHR_MEM, health.pid_mem_shared_memory_size as i64);
138-
set_gauge(&PROCESS_SECONDS, health.pid_process_seconds_total as i64);
139-
}
138+
139+
if let Ok(counter) = &*PROCESS_SECONDS {
140+
let new_val = health.pid_process_seconds_total as u64;
141+
counter.reset();
142+
counter.inc_by(new_val);
143+
}
144+
}
140145
}
141146

142147
pub fn scrape_system_health_metrics() {

0 commit comments

Comments
 (0)