A FastAPI application that provides system-level and application-level metrics monitoring in Prometheus format. Tracks CPU, memory, and HTTP request metrics while storing sample data in MongoDB.
- Monitors CPU and memory usage
- Tracks HTTP requests (counts, response statuses)
- Prometheus-compatible
/metrics
endpoint - MongoDB integration for storing/retrieving sample data
- Fully asynchronous and high-performance
Method | Path | Description |
---|---|---|
GET | / |
Root endpoint, returns a welcome message |
GET | /health |
Health check, returns ok |
GET | /metrics |
Prometheus metrics for monitoring |
POST | /data |
Store sample data in MongoDB |
GET | /data |
Retrieve all stored data from MongoDB |
- Install dependencies
pip install -r requirements.txt
-
Configure MongoDB Update
app/db.py
with your MongoDB URI. -
Run the app
uvicorn app.main:app --reload
Open in browser or via Postman/curl:
- Root:
http://127.0.0.1:8000/
- Health:
http://127.0.0.1:8000/health
- Metrics:
http://127.0.0.1:8000/metrics
- POST /data example:
{
"name": "Test Item",
"value": 123
}
- Asynchronous, production-ready FastAPI app
- Prometheus-compatible metrics for monitoring
- Persistent MongoDB storage for sample data
- Easy to extend with additional metrics or endpoints
- Request duration histograms and 95th percentile latency
- Request/response size tracking
- Additional system metrics: uptime, thread count, GC stats