diff options
| author | tv <tv@krebsco.de> | 2026-10-24 06:53:17 +0200 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-10-24 06:53:17 +0200 |
| commit | 8ee3b7f0d2f9b76cb24f0049431bd58d09d6c5a4 (patch) | |
| tree | 6e9774ff74634029309e6720e7c8eccce62766cf /src/api/stats/prometheus.rs | |
| parent | eeae01887aa7bf5ab4dc4d9c5dc90e06c465accd (diff) | |
add node aliases
Diffstat (limited to 'src/api/stats/prometheus.rs')
| -rw-r--r-- | src/api/stats/prometheus.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/api/stats/prometheus.rs b/src/api/stats/prometheus.rs index 16869f7..d29207c 100644 --- a/src/api/stats/prometheus.rs +++ b/src/api/stats/prometheus.rs @@ -68,6 +68,7 @@ fn flag(value: bool) -> f64 { /// What we show per peer. struct Peer { key: String, + alias: Option<String>, neighbour: bool, dormant: bool, last_seen_secs: Option<f64>, @@ -86,6 +87,7 @@ async fn peers(state: &AppState) -> Vec<Peer> { .iter() .map(|(key, peer_state)| (key.clone(), peer_state.clone())) .collect(); + let mut aliases = crate::swarm::members::aliases(&state.doc.read().await.doc); let mut peers = Vec::with_capacity(snapshot.len()); for (key, peer_state) in snapshot { let neighbour = crate::swarm::topology::is_neighbour(state, &key); @@ -111,6 +113,7 @@ async fn peers(state: &AppState) -> Vec<Peer> { incidents: peer_state.incidents, rtt_secs, throughput, + alias: aliases.remove(&key), key, }); } @@ -139,6 +142,22 @@ fn traffic_series(traffic: &PeerTraffic) -> Vec<(&'static str, &'static str, Cou pub(super) async fn render(state: &AppState, stats: &StatsResponse) -> String { let mut out = Out::default(); + // Names for joining (`* on(peer) group_left(alias) continuum_peer_info`), kept out + // of the other series so a rename doesn't start new ones. + out.family( + "info", + "gauge", + "This node's public key and alias (always 1).", + ); + out.sample( + "info", + &[ + ("public_key", &stats.public_key), + ("alias", stats.alias.as_deref().unwrap_or("")), + ], + 1.0, + ); + out.single( "uptime_seconds", "gauge", @@ -342,6 +361,22 @@ pub(super) async fn render(state: &AppState, stats: &StatsResponse) -> String { let peers = peers(state).await; + out.family( + "peer_info", + "gauge", + "A peer's alias from the member list (always 1).", + ); + for peer in &peers { + out.sample( + "peer_info", + &[ + ("peer", &peer.key), + ("alias", peer.alias.as_deref().unwrap_or("")), + ], + 1.0, + ); + } + out.family("peer_neighbour", "gauge", "1 if the peer is a neighbour."); for peer in &peers { out.sample( |
