This project is a fork of Kludex's repository, which originally provides a way to integrate Prometheus + Grafana with a FastAPI application. This repository extends the original functionality by providing integration with Promtail and Grafana Loki for observability of the FastAPI application:
- integration with UV to manage project requirements;
- upgraded FastAPI application to provide CRUD operations on users achieved by FastCRUD;
- integration with SQLModel to store user data in PostgreSQL database;
- basic admin interface based on SQLAdmin package;
- Nginx for hosting static data in the dockerized environment.
- Python 3.12
- UV package manager
- Docker and Docker Compose plugin
The application can be configured using environment variables defined in the .env file. Key configurations include:
- settings for FastAPI application;
- settings for PostgreSQL;
- settings for Prometheus and Grafana.
Use .env.example file as a template to create your own .env file.
Once the configuration file is set up, you can deploy the application using Docker Compose:
docker compose up -d
The will start the following services:
- app - FastAPI application;
- db - PostgreSQL database to store data for the FastAPI application;
- promtail - Promtail service to collect logs from the FastAPI application and send them to Grafana Loki;
- loki - Grafana Loki service to store logs collected by Promtail;
- prometheus - Prometheus service to scrape metrics from the FastAPI application;
- grafana - Grafana service to visualize metrics and logs;
- nginx - Nginx service to serve static files.
Once all services are up and running, you can access the following endpoints:
- API Docs: http://localhost:8080/docs
- Admin UI: http://localhost:8080/admin
- Prometheus: http://localhost:9090
- Grafana: http://localhost:3000 (use credentials, set in the .env file)
- Grafana Loki: http://localhost:3100
Once all the services are up and running, go to Grafana, navigate to Dashboards -> Services -> FastAPI Dashboard and start monitoring and observing your FastAPI application:
and don't miss out the live logs of the FastAPI application in the bottom of the dashboard:
- Original FastAPI-Prometheus-Grafana repository provided by Kludex
- UV package manager
- Prometheus FastAPI Instrumentator
- FastCRUD for automatic CRUD operations
- SQLModel for the ORM
- SQLAdmin for the admin interface
This project is licensed under the MIT License - see the LICENSE file for details.


