This project demonstrates how to set up a load testing and monitoring stack using:
- FastAPI β sample web app (our test subject)
- Locust β simulate user traffic
- Locust Exporter β expose metrics in Prometheus format
- Prometheus β collect & store metrics
- Grafana β visualize performance trends
I also wrote a detailed article explaining this setup step by step on Medium:
From Stress to Success: Load Testing Python Apps & Visualizing Performance
server/
βββ app.py # FastAPI sample app
βββ locustfile.py # Locust test definition (user behavior)
βββ prometheus.yml # Prometheus scrape config
βββ docker-compose.yml # Combined setup (exporter, Prometheus, Grafana)
βββ poetry.lock # Dependency lock file (Poetry)
βββ pyproject.toml # Python project dependencies
- Docker + Docker Compose
- Python 3.9+ (if running app/Locust locally)
- Poetry for dependency management
cd serverpoetry install
poetry run uvicorn app:app --host 0.0.0.0 --port 8000App available at β http://localhost:8000
poetry run locust -f locustfile.py --host=http://localhost:8000Locust UI β http://localhost:8089
docker compose upServices available at:
- Locust Exporter β http://localhost:9646/metrics
- Prometheus β http://localhost:9090
- Grafana β http://localhost:3000
Default Grafana login:
username: admin
password: admin
In Grafana:
- Add Prometheus datasource β
http://prometheus:9090 - Import or create dashboards with queries like:
- Requests per second:
rate(locust_requests_total[1m]) - Avg response time:
locust_response_time_seconds_avg - 95th percentile latency:
locust_response_time_seconds_percentile_95 - Failure rate:
rate(locust_failures_total[5m])
- How to simulate user traffic against a Python web app
- How to expose Locust metrics in Prometheus format
- How to scrape and visualize load test data over time
- How to spot performance bottlenecks before production
MIT β feel free to fork and adapt.