Skip to content

Commit f8dbe85

Browse files
authored
Move kstat-sampler self-stat timeseries to TOML (#6033)
1 parent 7cbb741 commit f8dbe85

File tree

2 files changed

+48
-25
lines changed

2 files changed

+48
-25
lines changed

oximeter/instruments/src/kstat/sampler.rs

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,32 +46,13 @@ use tokio::time::Sleep;
4646
// The `KstatSampler` generates some statistics about its own operation, mostly
4747
// for surfacing failures to collect and dropped samples.
4848
mod self_stats {
49+
oximeter::use_timeseries!("kstat-sampler.toml");
4950
use super::BTreeMap;
5051
use super::Cumulative;
5152
use super::TargetId;
52-
53-
/// Information identifying this kstat sampler.
54-
#[derive(Debug, oximeter::Target)]
55-
pub struct KstatSampler {
56-
/// The hostname (or zonename) of the host machine.
57-
pub hostname: String,
58-
}
59-
60-
/// The total number of samples dropped for a single target.
61-
#[derive(Debug, oximeter::Metric)]
62-
pub struct SamplesDropped {
63-
/// The ID of the target being tracked.
64-
pub target_id: u64,
65-
/// The name of the target being tracked.
66-
pub target_name: String,
67-
pub datum: Cumulative<u64>,
68-
}
69-
70-
/// The cumulative number of expired targets.
71-
#[derive(Debug, oximeter::Metric)]
72-
pub struct ExpiredTargets {
73-
pub datum: Cumulative<u64>,
74-
}
53+
pub use kstat_sampler::ExpiredTargets;
54+
pub use kstat_sampler::KstatSampler;
55+
pub use kstat_sampler::SamplesDropped;
7556

7657
#[derive(Debug)]
7758
pub struct SelfStats {
@@ -85,7 +66,7 @@ mod self_stats {
8566
impl SelfStats {
8667
pub fn new(hostname: String) -> Self {
8768
Self {
88-
target: KstatSampler { hostname },
69+
target: KstatSampler { hostname: hostname.into() },
8970
drops: BTreeMap::new(),
9071
expired: ExpiredTargets { datum: Cumulative::new(0) },
9172
}
@@ -797,7 +778,7 @@ impl KstatSamplerWorker {
797778
*drops += n_overflow_samples as u64;
798779
let metric = self_stats::SamplesDropped {
799780
target_id: target_id.0,
800-
target_name,
781+
target_name: target_name.into(),
801782
datum: *drops,
802783
};
803784
let sample = match Sample::new(&stats.target, &metric) {
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
format_version = 1
2+
3+
[target]
4+
name = "kstat_sampler"
5+
description = "A software object sampling kernel statistics"
6+
authz_scope = "fleet"
7+
versions = [
8+
{ version = 1, fields = [ "hostname" ] },
9+
]
10+
11+
[[metrics]]
12+
name = "samples_dropped"
13+
description = "Total number of samples dropped for a single tracked target"
14+
units = "count"
15+
datum_type = "cumulative_u64"
16+
versions = [
17+
{ added_in = 1, fields = [ "target_id", "target_name" ] }
18+
]
19+
20+
[[metrics]]
21+
name = "expired_targets"
22+
description = """\
23+
Total number of targets that have expired. Targets may expire \
24+
after either a limited number of unsuccessful sampling attempts, \
25+
or after a duration of unsuccessful sampling."""
26+
units = "count"
27+
datum_type = "cumulative_u64"
28+
versions = [
29+
{ added_in = 1, fields = [ ] }
30+
]
31+
32+
[fields.hostname]
33+
type = "string"
34+
description = "The hostname (or zonename) of the machine hosting the sampler"
35+
36+
[fields.target_id]
37+
type = "u64"
38+
description = "The unique ID of the target being tracked"
39+
40+
[fields.target_name]
41+
type = "string"
42+
description = "The name of the target being tracked"

0 commit comments

Comments
 (0)