Skip to content

The "FastAPI Monitoring Stack" is a complete set of tools that work together to watch over a FastAPI application.

Notifications You must be signed in to change notification settings

primegen-git/fastapi-monitoring-stack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastAPI Monitoring Stack

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.

Features

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

Architecture

Project Architecture

Data Flow

Data Flow

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

Directory Structure

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

Getting Started

Prerequisites

  • Docker & Docker Compose

Quick Start

  1. Clone the repository
    git clone https://github.com/primegen-git/fastapi-monitoring-stack.git
    cd fastapi-monitoring-stack
  2. Build and start all services
    docker-compose up --build
  3. Access the services:

Endpoints

  • / : Basic welcome endpoint
  • /metrics : Prometheus metrics endpoint

Testing

You can use the provided test.sh script to generate load:

bash test.sh

Monitoring & Observability

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

Customization

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

Screenshots

Total Request Count Average Request Latency Request Trace Logs

About

The "FastAPI Monitoring Stack" is a complete set of tools that work together to watch over a FastAPI application.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published