Skip to content

Commit

Permalink
Move kstat-sampler self-stat timeseries to TOML (#6033)
Browse files Browse the repository at this point in the history
  • Loading branch information
bnaecker authored Jul 10, 2024
1 parent 7cbb741 commit f8dbe85
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 25 deletions.
31 changes: 6 additions & 25 deletions oximeter/instruments/src/kstat/sampler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64>,
}

/// The cumulative number of expired targets.
#[derive(Debug, oximeter::Metric)]
pub struct ExpiredTargets {
pub datum: Cumulative<u64>,
}
pub use kstat_sampler::ExpiredTargets;
pub use kstat_sampler::KstatSampler;
pub use kstat_sampler::SamplesDropped;

#[derive(Debug)]
pub struct SelfStats {
Expand All @@ -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) },
}
Expand Down Expand Up @@ -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) {
Expand Down
42 changes: 42 additions & 0 deletions oximeter/oximeter/schema/kstat-sampler.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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. Targets may expire \
after either a limited number of unsuccessful sampling attempts, \
or after a duration of unsuccessful sampling."""
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"

0 comments on commit f8dbe85

Please sign in to comment.