A complete monitoring stack for FastAPI applications using Docker, Prometheus, Grafana, Loki, Jaeger, and OpenTelemetry. This project provides real-time metrics, distributed tracing, and log aggregation for your FastAPI.
- FastAPI: High-performance Python web framework.
- Prometheus: Metrics collection and monitoring.
- Grafana: Visualization of metrics and logs.
- Loki & Promtail: Centralized log aggregation.
- Jaeger: Distributed tracing for request flows.
- OpenTelemetry: Instrumentation for metrics and traces.
- Docker Compose: Easy orchestration of all services.
- FastAPI app exposes metrics and traces.
- Prometheus scrapes metrics from FastAPI.
- Grafana visualizes metrics and logs from Prometheus and Loki.
- Loki aggregates logs collected by Promtail from Docker containers.
- Jaeger receives traces from FastAPI via OpenTelemetry.
code/ # FastAPI app, Dockerfile, requirements
prometheus/ # Prometheus config
loki/ # Promtail config
assets/ # Architecture and metrics diagrams
vibe_venv/ # Python virtual environment (local)
docker-compose.yml # Orchestration of all services
- Docker & Docker Compose
- Clone the repository
git clone https://github.com/primegen-git/fastapi-monitoring-stack.git cd fastapi-monitoring-stack
- Build and start all services
docker-compose up --build
- Access the services:
- FastAPI: http://localhost:8000
- Prometheus: http://localhost:9090
- Grafana: http://localhost:3000
- Jaeger: http://localhost:16686
/
: Basic welcome endpoint/metrics
: Prometheus metrics endpoint
You can use the provided test.sh
script to generate load:
bash test.sh
- Metrics: Prometheus scrapes
/metrics
from FastAPI. View in Prometheus or Grafana. - Tracing: Jaeger UI shows distributed traces for requests.
- Logs: Loki aggregates logs; view in Grafana.
- Edit
code/main.py
to add more endpoints or custom metrics. - Update
prometheus/prometheus.yml
for scrape configs. - Modify
loki/promtail-config.yml
for log sources.