Skip to main content

running_process/broker/server/
metrics.rs

1//! Frozen OpenMetrics names for the v1 broker.
2
3/// Prefix for every v1 broker metric.
4pub const METRIC_PREFIX: &str = "running_process_broker_v1_";
5
6/// Metric type used by the OpenMetrics renderer.
7#[derive(Clone, Copy, Debug, PartialEq, Eq)]
8pub enum MetricKind {
9    /// Monotonic counter.
10    Counter,
11    /// Gauge value.
12    Gauge,
13    /// Histogram series.
14    Histogram,
15}
16
17/// One frozen metric descriptor.
18#[derive(Clone, Copy, Debug, PartialEq, Eq)]
19pub struct MetricDescriptor {
20    /// OpenMetrics name.
21    pub name: &'static str,
22    /// Metric type.
23    pub kind: MetricKind,
24    /// Label names in stable render order.
25    pub labels: &'static [&'static str],
26}
27
28const SERVICE_VERSION_OUTCOME: &[&str] = &["service", "version", "outcome"];
29const SERVICE_VERSION: &[&str] = &["service", "version"];
30const SERVICE: &[&str] = &["service"];
31const NO_LABELS: &[&str] = &[];
32
33/// Hello requests by service, version, and outcome.
34pub const HELLO_TOTAL: MetricDescriptor = MetricDescriptor {
35    name: "running_process_broker_v1_hello_total",
36    kind: MetricKind::Counter,
37    labels: SERVICE_VERSION_OUTCOME,
38};
39
40/// Hello latency histogram by service.
41pub const HELLO_DURATION_SECONDS: MetricDescriptor = MetricDescriptor {
42    name: "running_process_broker_v1_hello_duration_seconds",
43    kind: MetricKind::Histogram,
44    labels: SERVICE,
45};
46
47/// Live backend count by service.
48pub const ACTIVE_BACKENDS: MetricDescriptor = MetricDescriptor {
49    name: "running_process_broker_v1_active_backends",
50    kind: MetricKind::Gauge,
51    labels: SERVICE,
52};
53
54/// Backend spawn attempts by service, version, and outcome.
55pub const SPAWN_ATTEMPTS_TOTAL: MetricDescriptor = MetricDescriptor {
56    name: "running_process_broker_v1_spawn_attempts_total",
57    kind: MetricKind::Counter,
58    labels: SERVICE_VERSION_OUTCOME,
59};
60
61/// Remaining spawn budget by service and version.
62pub const SPAWN_BUDGET_REMAINING: MetricDescriptor = MetricDescriptor {
63    name: "running_process_broker_v1_spawn_budget_remaining",
64    kind: MetricKind::Gauge,
65    labels: SERVICE_VERSION,
66};
67
68/// Open broker control-plane connections.
69pub const CONNECTIONS_OPEN: MetricDescriptor = MetricDescriptor {
70    name: "running_process_broker_v1_connections_open",
71    kind: MetricKind::Gauge,
72    labels: NO_LABELS,
73};
74
75/// Process file-descriptor or handle pressure ratio.
76pub const FD_USAGE_RATIO: MetricDescriptor = MetricDescriptor {
77    name: "running_process_broker_v1_fd_usage_ratio",
78    kind: MetricKind::Gauge,
79    labels: NO_LABELS,
80};
81
82/// Broker process uptime in seconds.
83pub const UPTIME_SECONDS: MetricDescriptor = MetricDescriptor {
84    name: "running_process_broker_v1_uptime_seconds",
85    kind: MetricKind::Gauge,
86    labels: NO_LABELS,
87};
88
89/// Complete frozen metric set.
90pub const BROKER_METRICS: &[MetricDescriptor] = &[
91    HELLO_TOTAL,
92    HELLO_DURATION_SECONDS,
93    ACTIVE_BACKENDS,
94    SPAWN_ATTEMPTS_TOTAL,
95    SPAWN_BUDGET_REMAINING,
96    CONNECTIONS_OPEN,
97    FD_USAGE_RATIO,
98    UPTIME_SECONDS,
99];