Skip to content

prathamlahoti123/fastapi-prometheus-grafana

 
 

Repository files navigation

Pytest Checked with mypy Linter Ruff

About

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:

Architecture Diagram

Other Features

  • 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.

System Requirements

  • Python 3.12
  • UV package manager
  • Docker and Docker Compose plugin

Configuration

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.

Deployment

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.

Usage

Once all services are up and running, you can access the following endpoints:

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:

Grafana Dashboard

and don't miss out the live logs of the FastAPI application in the bottom of the dashboard:

FastAPI Application Logs

References

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

FasAPI + Prometheus + Grafana

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 96.4%
  • Dockerfile 3.6%