Skip to content

Alleny244/locust-grafana-prometheus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 

Repository files navigation

Load Testing Demo with Locust, Prometheus & Grafana

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


πŸ“‚ Project Structure

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

πŸ›  Prerequisites


β–ΆGetting Started

1. Move into the project folder

cd server

2. Run the FastAPI app

poetry install
poetry run uvicorn app:app --host 0.0.0.0 --port 8000

App available at β†’ http://localhost:8000


3. Run Locust (load testing)

poetry run locust -f locustfile.py --host=http://localhost:8000

Locust UI β†’ http://localhost:8089


4. Start Monitoring Stack (Exporter, Prometheus, Grafana)

docker compose up

Services available at:

Default Grafana login:

username: admin
password: admin

πŸ“Š Visualizing Performance

In Grafana:

  1. Add Prometheus datasource β†’ http://prometheus:9090
  2. 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])
    

What You’ll Learn

  • 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

πŸ“œ License

MIT β€” feel free to fork and adapt.

About

Load testing demo project using FastAPI, Locust, Prometheus, and Grafana. Simulate user traffic, collect metrics, and visualize performance with a complete monitoring stack.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages