From ce8e74d5eb2770e94491d7102ab1c249c46d3f03 Mon Sep 17 00:00:00 2001 From: Benjamin Naecker Date: Wed, 10 Jul 2024 01:08:48 +0000 Subject: [PATCH] Move kstat-sampler self-stat timeseries to TOML --- oximeter/instruments/src/kstat/sampler.rs | 31 ++++------------ oximeter/oximeter/schema/kstat-sampler.toml | 39 +++++++++++++++++++++ 2 files changed, 45 insertions(+), 25 deletions(-) create mode 100644 oximeter/oximeter/schema/kstat-sampler.toml diff --git a/oximeter/instruments/src/kstat/sampler.rs b/oximeter/instruments/src/kstat/sampler.rs index 74770a6225f..92466758c1c 100644 --- a/oximeter/instruments/src/kstat/sampler.rs +++ b/oximeter/instruments/src/kstat/sampler.rs @@ -46,32 +46,13 @@ use tokio::time::Sleep; // The `KstatSampler` generates some statistics about its own operation, mostly // for surfacing failures to collect and dropped samples. mod self_stats { + oximeter::use_timeseries!("kstat-sampler.toml"); use super::BTreeMap; use super::Cumulative; use super::TargetId; - - /// Information identifying this kstat sampler. - #[derive(Debug, oximeter::Target)] - pub struct KstatSampler { - /// The hostname (or zonename) of the host machine. - pub hostname: String, - } - - /// The total number of samples dropped for a single target. - #[derive(Debug, oximeter::Metric)] - pub struct SamplesDropped { - /// The ID of the target being tracked. - pub target_id: u64, - /// The name of the target being tracked. - pub target_name: String, - pub datum: Cumulative, - } - - /// The cumulative number of expired targets. - #[derive(Debug, oximeter::Metric)] - pub struct ExpiredTargets { - pub datum: Cumulative, - } + pub use kstat_sampler::ExpiredTargets; + pub use kstat_sampler::KstatSampler; + pub use kstat_sampler::SamplesDropped; #[derive(Debug)] pub struct SelfStats { @@ -85,7 +66,7 @@ mod self_stats { impl SelfStats { pub fn new(hostname: String) -> Self { Self { - target: KstatSampler { hostname }, + target: KstatSampler { hostname: hostname.into() }, drops: BTreeMap::new(), expired: ExpiredTargets { datum: Cumulative::new(0) }, } @@ -797,7 +778,7 @@ impl KstatSamplerWorker { *drops += n_overflow_samples as u64; let metric = self_stats::SamplesDropped { target_id: target_id.0, - target_name, + target_name: target_name.into(), datum: *drops, }; let sample = match Sample::new(&stats.target, &metric) { diff --git a/oximeter/oximeter/schema/kstat-sampler.toml b/oximeter/oximeter/schema/kstat-sampler.toml new file mode 100644 index 00000000000..3b0cc3c8148 --- /dev/null +++ b/oximeter/oximeter/schema/kstat-sampler.toml @@ -0,0 +1,39 @@ +format_version = 1 + +[target] +name = "kstat_sampler" +description = "A software object sampling kernel statistics" +authz_scope = "fleet" +versions = [ + { version = 1, fields = [ "hostname" ] }, +] + +[[metrics]] +name = "samples_dropped" +description = "Total number of samples dropped for a single tracked target" +units = "count" +datum_type = "cumulative_u64" +versions = [ + { added_in = 1, fields = [ "target_id", "target_name" ] } +] + +[[metrics]] +name = "expired_targets" +description = "Total number of targets that have expired" +units = "count" +datum_type = "cumulative_u64" +versions = [ + { added_in = 1, fields = [ ] } +] + +[fields.hostname] +type = "string" +description = "The hostname (or zonename) of the machine hosting the sampler" + +[fields.target_id] +type = "u64" +description = "The unique ID of the target being tracked" + +[fields.target_name] +type = "string" +description = "The name of the target being tracked"