diff options
Diffstat (limited to 'src/http_health.rs')
| -rw-r--r-- | src/http_health.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/http_health.rs b/src/http_health.rs index 0cdfeb5..d3f5df2 100644 --- a/src/http_health.rs +++ b/src/http_health.rs | |||
| @@ -12,6 +12,7 @@ pub struct HealthState { | |||
| 12 | pub cycle_count: watch::Receiver<u64>, | 12 | pub cycle_count: watch::Receiver<u64>, |
| 13 | pub last_cycle_ok: watch::Receiver<bool>, | 13 | pub last_cycle_ok: watch::Receiver<bool>, |
| 14 | pub db_path: String, | 14 | pub db_path: String, |
| 15 | pub nip46_client: Option<Arc<crate::nip46::Nip46Client>>, | ||
| 15 | } | 16 | } |
| 16 | 17 | ||
| 17 | pub async fn start_health_server(port: u16, state: Arc<HealthState>) -> anyhow::Result<()> { | 18 | pub async fn start_health_server(port: u16, state: Arc<HealthState>) -> anyhow::Result<()> { |
| @@ -31,10 +32,27 @@ async fn health_handler(State(state): State<Arc<HealthState>>) -> Json<Value> { | |||
| 31 | let cycle_count = *state.cycle_count.borrow(); | 32 | let cycle_count = *state.cycle_count.borrow(); |
| 32 | let last_ok = *state.last_cycle_ok.borrow(); | 33 | let last_ok = *state.last_cycle_ok.borrow(); |
| 33 | 34 | ||
| 35 | let nip46_sessions = if let Some(ref client) = state.nip46_client { | ||
| 36 | let statuses = client.get_status().await; | ||
| 37 | statuses | ||
| 38 | .into_iter() | ||
| 39 | .map(|s| { | ||
| 40 | json!({ | ||
| 41 | "npub": s.npub, | ||
| 42 | "connected": s.connected, | ||
| 43 | "pairing_uri": s.pairing_uri, | ||
| 44 | }) | ||
| 45 | }) | ||
| 46 | .collect::<Vec<_>>() | ||
| 47 | } else { | ||
| 48 | vec![] | ||
| 49 | }; | ||
| 50 | |||
| 34 | Json(json!({ | 51 | Json(json!({ |
| 35 | "status": if last_ok || cycle_count == 0 { "ok" } else { "degraded" }, | 52 | "status": if last_ok || cycle_count == 0 { "ok" } else { "degraded" }, |
| 36 | "uptime_secs": uptime.as_secs(), | 53 | "uptime_secs": uptime.as_secs(), |
| 37 | "cycle_count": cycle_count, | 54 | "cycle_count": cycle_count, |
| 38 | "last_cycle_ok": last_ok, | 55 | "last_cycle_ok": last_ok, |
| 56 | "nip46": nip46_sessions, | ||
| 39 | })) | 57 | })) |
| 40 | } | 58 | } |