upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/sync/metrics.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/sync/metrics.rs')
-rw-r--r--src/sync/metrics.rs29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/sync/metrics.rs b/src/sync/metrics.rs
index 453a79c..db7dd20 100644
--- a/src/sync/metrics.rs
+++ b/src/sync/metrics.rs
@@ -53,7 +53,7 @@ impl SyncMetrics {
53 let relay_connected = IntGaugeVec::new( 53 let relay_connected = IntGaugeVec::new(
54 Opts::new( 54 Opts::new(
55 "ngit_sync_relay_connected", 55 "ngit_sync_relay_connected",
56 "Relay connection status (1=connected, 0=disconnected)", 56 "Relay connection status (0=disconnected, 1=connecting, 2=syncing, 3=connected)",
57 ), 57 ),
58 &["relay"], 58 &["relay"],
59 )?; 59 )?;
@@ -201,6 +201,33 @@ impl SyncMetrics {
201 .set(state_value); 201 .set(state_value);
202 } 202 }
203 203
204 /// Record relay connection status change.
205 ///
206 /// Maps connection status to numeric values for Prometheus:
207 /// - Disconnected = 0 (not connected)
208 /// - Connecting = 1 (connection attempt in progress)
209 /// - Syncing = 2 (connected, historic sync in progress)
210 /// - Connected = 3 (connected, historic sync complete)
211 ///
212 /// This is separate from health state and provides more granular connection lifecycle tracking.
213 ///
214 /// # Arguments
215 ///
216 /// * `relay` - The relay URL
217 /// * `status` - The current connection status
218 pub fn record_connection_status(&self, relay: &str, status: super::ConnectionStatus) {
219 use super::ConnectionStatus;
220 let status_value = match status {
221 ConnectionStatus::Disconnected => 0,
222 ConnectionStatus::Connecting => 1,
223 ConnectionStatus::Syncing => 2,
224 ConnectionStatus::Connected => 3,
225 };
226 self.relay_connected
227 .with_label_values(&[relay])
228 .set(status_value);
229 }
230
204 /// Record relay failure count. 231 /// Record relay failure count.
205 /// 232 ///
206 /// # Arguments 233 /// # Arguments