Files
leleka/control-plane/src/prometheus.rs
T

51 lines
1.6 KiB
Rust

//! `GET /metrics?format=prometheus` (or an `Accept` that asks for `text/plain` / OpenMetrics): the same document as the
//! JSON `/metrics`, as Prometheus text exposition. A figure the document leaves `null` or does not have is not exposed
//! (Prometheus has no null; a missing series is the honest answer for "not measured"). Counters carry the `_total`
//! suffix and count since the control plane started; everything else is a gauge sampled when the endpoint is read.
//!
//! The table below is the contract: metric name, type, help, where it comes from in the JSON document, and a scale.
use std::fmt::Write;
use serde_json::Value;
pub const CONTENT_TYPE: &str = "text/plain; version=0.0.4; charset=utf-8";
#[derive(Clone, Copy, PartialEq, Eq)]
enum Kind {
Counter,
Gauge,
}
struct Series {
name: &'static str,
kind: Kind,
help: &'static str,
/// JSON pointer into the `/metrics` document.
from: &'static str,
scale: f64,
/// A fixed label, `name="value"` (several series of one metric differ only by it).
label: Option<(&'static str, &'static str)>,
}
/// The phase the engine reports, as a one-hot gauge (`idle`, `prefill`, `decode`).
const PHASES: [&str; 3] = ["idle", "prefill", "decode"];
/// NVML `nvmlClocksThrottleReason*` bits that cost speed.
const THROTTLE_REASONS: [(u64, &str); 5] = [
(0x4, "sw_power_cap"),
(0x8, "hw_slowdown"),
(0x20, "sw_thermal"),
(0x40, "hw_thermal"),
(0x80, "hw_power_brake"),
];
#[cfg(test)]
mod tests;
mod series;
use series::SERIES;
mod counter;
#[allow(unused_imports)]
pub use counter::*;