Skip to content

Commit

Permalink
feat: including container section when the process is in a container
Browse files Browse the repository at this point in the history
  • Loading branch information
bpetit committed Oct 28, 2022
1 parent 824edea commit 1f1cb49
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/exporters/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ impl Exporter for JSONExporter {
.takes_value(true);
options.push(arg);

let arg = Arg::with_name("containers")
.help("Monitor and apply labels for processes running as containers")
.long("containers")
.required(false)
.takes_value(false);
options.push(arg);

// the resulting labels of this option are not yet used by this exporter, activate this option once we display something interesting about it
//let arg = Arg::with_name("qemu")
// .help("Apply labels to metrics of processes looking like a Qemu/KVM virtual machine")
Expand Down Expand Up @@ -102,6 +109,13 @@ struct Consumer {
pid: i32,
consumption: f32,
timestamp: f64,
container: Option<Container>,
}
#[derive(Serialize, Deserialize)]
struct Container {
id: String,
runtime: String,
scheduler: String,
}
#[derive(Serialize, Deserialize)]
struct Host {
Expand Down Expand Up @@ -214,6 +228,24 @@ impl JSONExporter {
pid: process.pid,
consumption: format!("{}", metric.metric_value).parse::<f32>().unwrap(),
timestamp: metric.timestamp.as_secs_f64(),
container: match parameters.is_present("containers") {
true => metric.attributes.get("container_id").map(|container_id| Container {
id: String::from(container_id),
runtime: String::from(
metric
.attributes
.get("container_runtime")
.unwrap_or(&String::from("unknown")),
),
scheduler: String::from(
metric
.attributes
.get("container_scheduler")
.unwrap_or(&String::from("unknown")),
),
}),
false => None,
},
})
})
.collect::<Vec<_>>();
Expand Down

0 comments on commit 1f1cb49

Please sign in to comment.