A lightweight Flask REST API that exposes real-time system health metrics as JSON endpoints. Designed for DevOps monitoring, uptime checks, and system dashboards — deploy it on any Linux server and start querying CPU, memory, disk, and process data instantly.
| Method | Route | Auth | Description |
|---|---|---|---|
| GET | /health | No | Overall status: healthy or degraded |
| GET | /cpu | Yes | CPU usage %, core count, and frequency |
| GET | /memory | Yes | RAM total, available, used, and percent |
| GET | /disk | Yes | Disk total, used, free, and percent |
| GET | /processes | Yes | Top 10 processes by CPU usage |
| GET | /uptime | Yes | System uptime in human-readable format |
Auth requires an X-API-Key header. Set the API_KEY environment variable before running.
- Python 3.10+
- Flask 3.x
- psutil 5.x
Install dependencies:
pip install -r requirements.txtRun the server:
API_KEY=your-secret-key python app.pyServer starts on http://localhost:5000.
Check overall health (no auth required):
curl http://localhost:5000/health{"status": "healthy", "timestamp": "2024-11-15T14:32:01"}Query CPU metrics:
curl -H "X-API-Key: your-secret-key" http://localhost:5000/cpu{"cpu_percent": 12.4, "cpu_count": 8, "cpu_freq_mhz": 2400.0}Query memory usage:
curl -H "X-API-Key: your-secret-key" http://localhost:5000/memory{"total_gb": 16.0, "available_gb": 9.3, "used_gb": 6.7, "percent": 41.9}Top processes by CPU:
curl -H "X-API-Key: your-secret-key" http://localhost:5000/processes- The
/healthendpoint is intentionally unauthenticated for uptime monitor compatibility - All other endpoints require the
X-API-Keyheader - Never hardcode the API key — load it via environment variable in production