MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / write_prometheus

Method write_prometheus

nodedb/src/data/io/io_metrics.rs:108–155  ·  view source on GitHub ↗

Emit Prometheus text for all IO metrics. Produces: - `nodedb_io_queue_depth{priority=...}` gauges - `nodedb_io_wait_ns{priority=...}` histograms

(&self, out: &mut String)

Source from the content-addressed store, hash-verified

106 /// - `nodedb_io_queue_depth{priority=...}` gauges
107 /// - `nodedb_io_wait_ns{priority=...}` histograms
108 pub fn write_prometheus(&self, out: &mut String) {
109 use std::fmt::Write as _;
110
111 // ── Queue depth gauges ──
112 let _ = out.write_str(
113 "# HELP nodedb_io_queue_depth Pending IO task count per priority tier\n\
114 # TYPE nodedb_io_queue_depth gauge\n",
115 );
116 for (tier, label) in TIER_LABELS.iter().enumerate() {
117 let depth = self.queue_depth[tier].load(Ordering::Relaxed);
118 let _ = writeln!(
119 out,
120 r#"nodedb_io_queue_depth{{priority="{label}"}} {depth}"#
121 );
122 }
123
124 // ── IO wait histograms ──
125 // One histogram block per tier, le= values in seconds (Prometheus convention).
126 let _ = out.write_str(
127 "# HELP nodedb_io_wait_ns IO submission-to-completion latency per priority tier\n\
128 # TYPE nodedb_io_wait_ns histogram\n",
129 );
130 for (tier, label) in TIER_LABELS.iter().enumerate() {
131 let mut cumulative = 0u64;
132 for (i, &boundary_ns) in IO_WAIT_BUCKETS_NS.iter().enumerate() {
133 cumulative += self.buckets[tier][i].load(Ordering::Relaxed);
134 let le_s = boundary_ns as f64 / 1_000_000_000.0;
135 let _ = writeln!(
136 out,
137 r#"nodedb_io_wait_ns_bucket{{priority="{label}",le="{le_s:.9}"}} {cumulative}"#
138 );
139 }
140 let total = self.count[tier].load(Ordering::Relaxed);
141 let _ = writeln!(
142 out,
143 r#"nodedb_io_wait_ns_bucket{{priority="{label}",le="+Inf"}} {total}"#
144 );
145 let sum_s = self.sum_ns[tier].load(Ordering::Relaxed) as f64 / 1_000_000_000.0;
146 let _ = writeln!(
147 out,
148 r#"nodedb_io_wait_ns_sum{{priority="{label}"}} {sum_s:.9}"#
149 );
150 let _ = writeln!(
151 out,
152 r#"nodedb_io_wait_ns_count{{priority="{label}"}} {total}"#
153 );
154 }
155 }
156}
157
158impl Default for IoMetrics {

Callers

nothing calls this directly

Calls 2

iterMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected