Skip to content

Commit c1de391

Browse files
committed
thread labels through new metrics
Signed-off-by: Brian L. Troutwine <[email protected]>
1 parent 6575d56 commit c1de391

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

lading/src/observer/linux.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,10 @@ impl Sampler {
292292
let vsize: u64 = stats.vsize;
293293

294294
let labels = [
295-
("pid", format!("{pid}")),
296-
("exe", basename.clone()),
297-
("cmdline", cmdline.clone()),
298-
("comm", comm.clone()),
295+
(String::from("pid"), format!("{pid}")),
296+
(String::from("exe"), basename.clone()),
297+
(String::from("cmdline"), cmdline.clone()),
298+
(String::from("comm"), comm.clone()),
299299
];
300300

301301
// Number of pages that the process has in real memory.
@@ -363,8 +363,8 @@ impl Sampler {
363363
let labels = [
364364
("pid", format!("{pid}")),
365365
("exe", basename.clone()),
366-
("comm", comm.clone()),
367366
("cmdline", cmdline.clone()),
367+
("comm", comm.clone()),
368368
];
369369

370370
gauge!("smaps.rss.sum", &labels).set(measures.rss as f64);
@@ -404,7 +404,7 @@ impl Sampler {
404404
// using the same heuristic as kubernetes:
405405
// total_usage - inactive_file
406406
let cgroup_path = v2::get_path(pid).await?;
407-
v2::poll(cgroup_path).await?;
407+
v2::poll(cgroup_path, &labels).await?;
408408
}
409409

410410
gauge!("num_processes").set(total_processes as f64);

lading/src/observer/linux/cgroup/v2.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub(crate) async fn get_path(pid: i32) -> Result<PathBuf, Error> {
3939
}
4040

4141
/// Polls for any cgroup metrics that can be read, v2 version.
42-
pub(crate) async fn poll(path: PathBuf) -> Result<(), Error> {
42+
pub(crate) async fn poll(path: PathBuf, labels: &[(String, String)]) -> Result<(), Error> {
4343
let mut entries = fs::read_dir(&path).await?;
4444

4545
while let Some(entry) = entries.next_entry().await? {
@@ -65,10 +65,10 @@ pub(crate) async fn poll(path: PathBuf) -> Result<(), Error> {
6565
// name.
6666
if let Ok(value) = content.parse::<f64>() {
6767
// Single-valued
68-
gauge!(metric_prefix).set(value);
68+
gauge!(metric_prefix, labels).set(value);
6969
} else {
7070
// Key-value pairs
71-
if kv_pairs(content, &metric_prefix).is_err() {
71+
if kv_pairs(content, &metric_prefix, labels).is_err() {
7272
// File may fail to parse, for instance cgroup.controllers
7373
// is a list of strings.
7474
continue;
@@ -80,14 +80,14 @@ pub(crate) async fn poll(path: PathBuf) -> Result<(), Error> {
8080
Ok(())
8181
}
8282

83-
fn kv_pairs(content: &str, metric_prefix: &str) -> Result<(), Error> {
83+
fn kv_pairs(content: &str, metric_prefix: &str, labels: &[(String, String)]) -> Result<(), Error> {
8484
for line in content.lines() {
8585
let mut parts = line.split_whitespace();
8686
let key = parts.next().expect("malformed key-value pair");
8787
let value_str = parts.next().expect("malformed key-value pair");
8888
let value: f64 = value_str.parse()?;
8989
let metric_name = format!("{metric_prefix}.{key}");
90-
gauge!(metric_name).set(value);
90+
gauge!(metric_name, labels).set(value);
9191
}
9292
Ok(())
9393
}

0 commit comments

Comments
 (0)