aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/api/stats/prometheus.rs79
1 files changed, 39 insertions, 40 deletions
diff --git a/src/api/stats/prometheus.rs b/src/api/stats/prometheus.rs
index 9180d9d..0b770bd 100644
--- a/src/api/stats/prometheus.rs
+++ b/src/api/stats/prometheus.rs
@@ -48,6 +48,32 @@ impl Out {
let _ = writeln!(self.0, " {value}");
}
+ /// One histogram's series (its family declared before): each bucket counting what
+ /// fell into it and every one before (upper bounds in seconds, the last unbounded),
+ /// the sum (seconds) and the count.
+ fn histogram(
+ &mut self,
+ name: &str,
+ labels: &[(&str, &str)],
+ buckets: impl Iterator<Item = (Option<f64>, u64)>,
+ sum: f64,
+ count: u64,
+ ) {
+ let mut cumulative = 0;
+ for (le, in_bucket) in buckets {
+ cumulative += in_bucket;
+ let le = match le {
+ Some(seconds) => seconds.to_string(),
+ None => "+Inf".to_owned(),
+ };
+ let mut with_le = labels.to_vec();
+ with_le.push(("le", &le));
+ self.sample(&format!("{name}_bucket"), &with_le, cumulative as f64);
+ }
+ self.sample(&format!("{name}_sum"), labels, sum);
+ self.sample(&format!("{name}_count"), labels, count as f64);
+ }
+
/// A family with one unlabelled sample.
fn single(&mut self, name: &str, kind: &str, help: &str, value: f64) {
self.family(name, kind, help);
@@ -444,28 +470,14 @@ pub(super) fn render(stats: &StatsResponse, list: &PeerListResponse) -> String {
);
let lock_wait = &document.lock_wait;
for (mode, waits) in [("read", &lock_wait.read), ("write", &lock_wait.write)] {
- let mut cumulative = 0;
- for (le_us, count) in waits.buckets() {
- cumulative += count;
- let le = match le_us {
- Some(us) => (us as f64 / 1e6).to_string(),
- None => "+Inf".to_owned(),
- };
- out.sample(
- "document_lock_wait_seconds_bucket",
- &[("mode", mode), ("le", &le)],
- cumulative as f64,
- );
- }
- out.sample(
- "document_lock_wait_seconds_sum",
+ out.histogram(
+ "document_lock_wait_seconds",
&[("mode", mode)],
+ waits
+ .buckets()
+ .map(|(le_us, count)| (le_us.map(|us| us as f64 / 1e6), count)),
waits.sum_us as f64 / 1e6,
- );
- out.sample(
- "document_lock_wait_seconds_count",
- &[("mode", mode)],
- waits.count as f64,
+ waits.count,
);
}
out.family(
@@ -730,28 +742,15 @@ pub(super) fn render(stats: &StatsResponse, list: &PeerListResponse) -> String {
"histogram",
"Time from a change's commit elsewhere until applied here (includes clock skew).",
);
- let mut cumulative = 0;
- for bucket in &propagation.buckets {
- cumulative += bucket.count;
- let le = match bucket.le_ms {
- Some(ms) => (ms as f64 / 1000.0).to_string(),
- None => "+Inf".to_owned(),
- };
- out.sample(
- "propagation_delay_seconds_bucket",
- &[("le", &le)],
- cumulative as f64,
- );
- }
- out.sample(
- "propagation_delay_seconds_sum",
+ out.histogram(
+ "propagation_delay_seconds",
&[],
+ propagation
+ .buckets
+ .iter()
+ .map(|bucket| (bucket.le_ms.map(|ms| ms as f64 / 1000.0), bucket.count)),
propagation.sum_ms as f64 / 1000.0,
- );
- out.sample(
- "propagation_delay_seconds_count",
- &[],
- propagation.count as f64,
+ propagation.count,
);
out.single(
"propagation_clock_ahead_total",