Skip to content

Commit

Permalink
rename cpu_total to cpu_secs
Browse files Browse the repository at this point in the history
  • Loading branch information
flaneur2020 committed May 20, 2024
1 parent 9334f93 commit 8eb7695
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/common/base/src/runtime/metrics/process_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ impl Collector for ProcessCollector {
None => return Ok(()),
};

let cpu_total = ConstCounter::new(stat.cpu_total);
let cpu_total_encoder = encoder.encode_descriptor(
let cpu_secs = ConstCounter::new(stat.cpu_secs);
let cpu_secs_encoder = encoder.encode_descriptor(
"process_cpu_seconds_total",
"Total user and system CPU time spent in seconds.",
None,
cpu_total.metric_type(),
cpu_secs.metric_type(),
)?;
cpu_total.encode(cpu_total_encoder)?;
cpu_secs.encode(cpu_secs_encoder)?;

let open_fds = ConstGauge::new(stat.open_fds as f64);
let open_fds_encoder = encoder.encode_descriptor(
Expand Down Expand Up @@ -91,7 +91,7 @@ impl Collector for ProcessCollector {

#[derive(Clone, Default)]
pub struct ProcessStat {
pub cpu_total: u64,
pub cpu_secs: u64,
pub open_fds: u64,
pub max_fds: u64,
pub vsize: u64,
Expand Down Expand Up @@ -147,7 +147,7 @@ fn dump_linux_process_stat() -> Option<ProcessStat> {
let rss = stat.rss * (page_size as u64);

// cpu time
let cpu_total = (stat.utime + stat.stime) / clk_tck as u64;
let cpu_secs = (stat.utime + stat.stime) as u64 / clk_tck as u64;

// start time
let start_time = stat.starttime as i64 * clk_tck;
Expand All @@ -160,7 +160,7 @@ fn dump_linux_process_stat() -> Option<ProcessStat> {
max_fds,
vsize,
rss,
cpu_total,
cpu_secs,
start_time,
threads_num,
})
Expand Down
1 change: 1 addition & 0 deletions src/query/service/tests/it/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ async fn test_metric_server() -> databend_common_exception::Result<()> {
fn test_process_collector() {
let stat = dump_process_stat().unwrap();

assert!(stat.cpu_secs > 0.0);
assert!(stat.max_fds > 0);
assert!(stat.vsize > 0);
assert!(stat.rss > 0);
Expand Down

0 comments on commit 8eb7695

Please sign in to comment.