MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / record_metrics

Function record_metrics

crates/openshell-server/src/readiness.rs:203–223  ·  view source on GitHub ↗
(state: &HealthState)

Source from the content-addressed store, hash-verified

201}
202
203fn record_metrics(state: &HealthState) {
204 let (healthy, outcome_label, latency_seconds) = match state {
205 HealthState::Initializing => return,
206 HealthState::Healthy { latency_ms } => {
207 (true, "success", duration_seconds_from_ms(*latency_ms))
208 }
209 HealthState::Unhealthy(HealthError::Unavailable { latency_ms }) => {
210 (false, "db_error", duration_seconds_from_ms(*latency_ms))
211 }
212 HealthState::Unhealthy(HealthError::Timeout) => {
213 (false, "timeout", DEFAULT_CHECK_TIMEOUT.as_secs_f64())
214 }
215 };
216
217 gauge!(METRIC_READINESS_DATABASE_HEALTHY).set(if healthy { 1.0 } else { 0.0 });
218 histogram!(
219 METRIC_READINESS_DATABASE_PROBE_DURATION_SECONDS,
220 METRIC_OUTCOME_LABEL => outcome_label
221 )
222 .record(latency_seconds);
223}
224
225fn duration_seconds_from_ms(ms: u64) -> f64 {
226 #[allow(clippy::cast_precision_loss)]

Callers 1

monitor_loopFunction · 0.85

Calls 2

duration_seconds_from_msFunction · 0.85
setMethod · 0.45

Tested by

no test coverage detected