Skip to content

Commit 34b4fbc

Browse files
committed
fix(metrics): align Prometheus metric names and units with conventions
- `nodedb_bridge_utilization` (integer percent) becomes `nodedb_bridge_utilization_ratio` (float 0.0–1.0). - `nodedb_compaction_throughput_bytes_sec` becomes `nodedb_compaction_throughput_bytes_per_second`. - `nodedb_mmap_major_faults` becomes `nodedb_mmap_major_faults_total` (counter suffix required by Prometheus naming conventions). - `shutdown_last_duration_ms{phase}` becomes `nodedb_shutdown_phase_duration_seconds{phase}` with millisecond values converted to fractional seconds. - `catalog_sanity_check_total` becomes `nodedb_catalog_sanity_check_total`. All references in `shutdown/bus.rs` and `main.rs` are updated to the new metric names.
1 parent 424cc87 commit 34b4fbc

6 files changed

Lines changed: 25 additions & 21 deletions

File tree

nodedb/src/control/metrics/prometheus/core.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ impl SystemMetrics {
7575
);
7676

7777
// ── Bridge ──
78-
gauge(
78+
gauge_f64(
7979
out,
80-
"nodedb_bridge_utilization",
81-
"SPSC bridge utilization percent",
82-
self.bridge_utilization.load(Ordering::Relaxed),
80+
"nodedb_bridge_utilization_ratio",
81+
"SPSC bridge utilization as a ratio (0.0–1.0)",
82+
self.bridge_utilization.load(Ordering::Relaxed) as f64 / 100.0,
8383
);
8484

8585
// ── Compaction ──
@@ -97,8 +97,8 @@ impl SystemMetrics {
9797
);
9898
gauge(
9999
out,
100-
"nodedb_compaction_throughput_bytes_sec",
101-
"Compaction throughput bytes/sec",
100+
"nodedb_compaction_throughput_bytes_per_second",
101+
"Compaction throughput bytes per second",
102102
self.compaction_throughput_bytes_sec.load(Ordering::Relaxed),
103103
);
104104

nodedb/src/control/metrics/prometheus/engines.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl SystemMetrics {
189189
// ── Contention ──
190190
counter(
191191
out,
192-
"nodedb_mmap_major_faults",
192+
"nodedb_mmap_major_faults_total",
193193
"mmap major page faults",
194194
self.mmap_major_faults.load(Ordering::Relaxed),
195195
);

nodedb/src/control/metrics/system.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ impl SystemMetrics {
489489
out
490490
}
491491

492-
/// Emit `shutdown_last_duration_ms{phase}` gauges.
492+
/// Emit `nodedb_shutdown_phase_duration_seconds{phase}` gauges.
493493
fn prometheus_shutdown_phases(&self, out: &mut String) {
494494
use std::fmt::Write as _;
495495
let m = self
@@ -500,17 +500,21 @@ impl SystemMetrics {
500500
return;
501501
}
502502
let _ = out.write_str(
503-
"# HELP shutdown_last_duration_ms Duration of each shutdown phase in the last graceful shutdown\n\
504-
# TYPE shutdown_last_duration_ms gauge\n",
503+
"# HELP nodedb_shutdown_phase_duration_seconds Duration of each shutdown phase in the last graceful shutdown\n\
504+
# TYPE nodedb_shutdown_phase_duration_seconds gauge\n",
505505
);
506506
let mut pairs: Vec<_> = m.iter().collect();
507507
pairs.sort_by(|a, b| a.0.cmp(b.0));
508508
for (phase, ms) in pairs {
509-
let _ = writeln!(out, r#"shutdown_last_duration_ms{{phase="{phase}"}} {ms}"#);
509+
let secs = *ms as f64 / 1_000.0;
510+
let _ = writeln!(
511+
out,
512+
r#"nodedb_shutdown_phase_duration_seconds{{phase="{phase}"}} {secs}"#
513+
);
510514
}
511515
}
512516

513-
/// Emit `catalog_sanity_check_total{registry,outcome}` labeled counters.
517+
/// Emit `nodedb_catalog_sanity_check_total{registry,outcome}` labeled counters.
514518
fn prometheus_catalog_sanity(&self, out: &mut String) {
515519
use std::fmt::Write as _;
516520
let m = self
@@ -521,15 +525,15 @@ impl SystemMetrics {
521525
return;
522526
}
523527
let _ = out.write_str(
524-
"# HELP catalog_sanity_check_total Catalog sanity check outcomes per registry\n\
525-
# TYPE catalog_sanity_check_total counter\n",
528+
"# HELP nodedb_catalog_sanity_check_total Catalog sanity check outcomes per registry\n\
529+
# TYPE nodedb_catalog_sanity_check_total counter\n",
526530
);
527531
let mut pairs: Vec<_> = m.iter().collect();
528532
pairs.sort_by(|a, b| a.0.cmp(b.0));
529533
for ((registry, outcome), count) in pairs {
530534
let _ = writeln!(
531535
out,
532-
r#"catalog_sanity_check_total{{registry="{registry}",outcome="{outcome}"}} {count}"#
536+
r#"nodedb_catalog_sanity_check_total{{registry="{registry}",outcome="{outcome}"}} {count}"#
533537
);
534538
}
535539
}

nodedb/src/control/otel/exporter.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,13 @@ fn build_metrics_request(metrics: &SystemMetrics, node_id: u64) -> ExportMetrics
129129
now_ns,
130130
),
131131
gauge_metric(
132-
"nodedb_wal_fsync_latency_us",
133-
metrics.wal_fsync_latency_micros.load(Ordering::Relaxed) as f64,
132+
"nodedb_wal_fsync_latency_seconds",
133+
metrics.wal_fsync_latency_micros.load(Ordering::Relaxed) as f64 / 1_000_000.0,
134134
now_ns,
135135
),
136136
gauge_metric(
137-
"nodedb_bridge_utilization",
138-
metrics.bridge_utilization.load(Ordering::Relaxed) as f64,
137+
"nodedb_bridge_utilization_ratio",
138+
metrics.bridge_utilization.load(Ordering::Relaxed) as f64 / 100.0,
139139
now_ns,
140140
),
141141
gauge_metric(

nodedb/src/control/shutdown/bus.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ impl ShutdownBus {
322322
*self.phase_tx.borrow()
323323
}
324324

325-
/// Wire a metrics sink so the bus records `shutdown_last_duration_ms{phase}`
325+
/// Wire a metrics sink so the bus records `nodedb_shutdown_phase_duration_seconds{phase}`
326326
/// for each phase transition during shutdown.
327327
///
328328
/// Must be called before `initiate()` to have effect. Idempotent.

nodedb/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ async fn main() -> anyhow::Result<()> {
640640
// existing `watch::Receiver<bool>` subscribers wake up as well.
641641
let (shutdown_bus, _shutdown_bus_handle) =
642642
nodedb::control::shutdown::ShutdownBus::new(Arc::clone(&shared.shutdown));
643-
// Wire system metrics so the bus records `shutdown_last_duration_ms{phase}`
643+
// Wire system metrics so the bus records `nodedb_shutdown_phase_duration_seconds{phase}`
644644
// for each phase transition during graceful shutdown.
645645
shutdown_bus.set_metrics(Arc::clone(&system_metrics));
646646

0 commit comments

Comments
 (0)