diff --git a/Cargo.lock b/Cargo.lock index 0e59b06..a507e37 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -501,9 +501,9 @@ checksum = "518ef76f2f87365916b142844c16d8fefd85039bc5699050210a7778ee1cd1de" [[package]] name = "lustre_collector" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d06b4c22de6e9a045c0a26a2a87da29cd3b7731de83ca0fe206a1bed3d1235c0" +checksum = "d14041effdd770419d421860048f000dc849b470a482e416b0dd51c9bf3e225d" dependencies = [ "clap", "combine", diff --git a/src/lib.rs b/src/lib.rs index 020c2d7..d565bda 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,7 @@ pub mod brw_stats; pub mod jobstats; pub mod lnet; +pub mod service; pub mod stats; use brw_stats::build_target_stats; @@ -8,6 +9,7 @@ use lnet::build_lnet_stats; use lustre_collector::{LNetStat, LNetStatGlobal, Record, TargetStat, TargetVariant}; use num_traits::Num; use prometheus_exporter_base::{prelude::*, Yes}; +use service::build_service_stats; use std::{collections::BTreeMap, fmt, ops::Deref, time::Duration}; #[derive(Debug, Clone, Copy)] @@ -123,6 +125,9 @@ pub fn build_lustre_stats(output: Vec, time: Duration) -> String { lustre_collector::Record::Target(x) => { build_target_stats(x, &mut stats_map, time); } + lustre_collector::Record::LustreService(x) => { + build_service_stats(x, &mut stats_map, time); + } } } diff --git a/src/service.rs b/src/service.rs new file mode 100644 index 0000000..199dd35 --- /dev/null +++ b/src/service.rs @@ -0,0 +1,49 @@ +use crate::{Metric, StatsMapExt}; +use lustre_collector::LustreServiceStats; +use prometheus_exporter_base::prelude::*; +use std::{collections::BTreeMap, ops::Deref, time::Duration}; + +static LDLM_CANCELD_STATS_SAMPLES: Metric = Metric { + name: "lustre_ldlm_canceld_stats", + help: "Gives information about LDLM Canceld service.", + r#type: MetricType::Counter, +}; + +static LDLM_CBD_STATS_SAMPLES: Metric = Metric { + name: "lustre_ldlm_cbd_stats", + help: "Gives information about LDLM Callback service.", + r#type: MetricType::Counter, +}; + +pub fn build_service_stats( + x: LustreServiceStats, + stats_map: &mut BTreeMap<&'static str, PrometheusMetric<'static>>, + time: Duration, +) { + match x { + LustreServiceStats::LdlmCanceld(xs) => { + for s in xs { + stats_map + .get_mut_metric(LDLM_CANCELD_STATS_SAMPLES) + .render_and_append_instance( + &PrometheusInstance::new() + .with_label("operation", s.name.deref()) + .with_value(s.samples) + .with_timestamp(time.as_millis()), + ); + } + } + LustreServiceStats::LdlmCbd(xs) => { + for s in xs { + stats_map + .get_mut_metric(LDLM_CBD_STATS_SAMPLES) + .render_and_append_instance( + &PrometheusInstance::new() + .with_label("operation", s.name.deref()) + .with_value(s.samples) + .with_timestamp(time.as_millis()), + ); + } + } + }; +}