Skip to content

feat: Add health check HTTP endpoint for monitoring#61

Merged
rexlunae merged 3 commits intomainfrom
feat/health-endpoint
Feb 17, 2026
Merged

feat: Add health check HTTP endpoint for monitoring#61
rexlunae merged 3 commits intomainfrom
feat/health-endpoint

Conversation

@rexlunae
Copy link
Copy Markdown
Owner

Summary

Adds HTTP health check server for remote monitoring from @aecs4u (PR #21).

Endpoints

GET /health

Simple health check returning 200 OK if gateway is running.

  • For load balancer health checks
  • Kubernetes liveness probes
  • Uptime monitoring services

GET /status

Detailed JSON status with metrics:

{
  "status": "healthy",
  "uptime_secs": 3600,
  "total_connections": 42,
  "active_connections": 3,
  "total_messages": 1234
}

HealthStats

Shared atomic counters tracked across connections:

  • start_time — Gateway start timestamp
  • uptime_secs() — Calculated uptime
  • total_connections — Cumulative connection count
  • active_connections — Current live connections
  • total_messages — Messages processed

Usage

use rustyclaw::gateway::health::{start_health_server, HealthStats};
use std::sync::Arc;

let stats = Arc::new(HealthStats::new());

// Start health server on separate port
tokio::spawn(start_health_server(
    "127.0.0.1:8081",
    stats.clone(),
    cancel_token,
));

Use Cases

  • Load balancer health checks
  • Kubernetes liveness/readiness probes
  • Uptime monitoring (Pingdom, UptimeRobot)
  • Prometheus metrics scraping
  • Remote status inspection

No New Dependencies

Uses existing: tokio, serde_json, anyhow

Attribution

Original implementation by @aecs4u

Adds HTTP health check server for remote monitoring from @aecs4u (PR #21).

## Endpoints

### GET /health
Simple health check returning 200 OK if gateway is running.
Useful for load balancer health checks.

### GET /status
Detailed JSON status with metrics:
```json
{
  "status": "healthy",
  "uptime_secs": 3600,
  "total_connections": 42,
  "active_connections": 3,
  "total_messages": 1234
}
```

## Features

### HealthStats
Shared statistics tracked across connections:
- Start time (for uptime calculation)
- Total connections (cumulative)
- Active connections (current)
- Total messages processed

### Usage
```rust
use rustyclaw::gateway::health::{start_health_server, HealthStats, SharedHealthStats};

let stats = Arc::new(HealthStats::new());

// Start health server on separate port
tokio::spawn(start_health_server(
    "127.0.0.1:8081",
    stats.clone(),
    cancel_token,
));

// Increment stats in connection handler
stats.total_connections.fetch_add(1, Ordering::Relaxed);
stats.active_connections.fetch_add(1, Ordering::Relaxed);
```

## Use Cases
- Load balancer health checks
- Uptime monitoring (Pingdom, UptimeRobot)
- Metrics collection
- Remote status inspection

## No New Dependencies
Uses existing: tokio, serde_json, anyhow

## Attribution
Original implementation by @aecs4u
@rexlunae rexlunae merged commit dd06543 into main Feb 17, 2026
10 checks passed
@rexlunae rexlunae deleted the feat/health-endpoint branch February 17, 2026 02:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant