Metrics Monitoring

Monitor Everything Before Failures Happen

Prometheus and Grafana with Docker Compose

Resources from Video Description

  • GitHub Repository - Starter code and configuration files
  • Written Summary: Current Page

📖 Extra Resources

Tutorials that explain how to instrument various types of applications to expose prometheus metrics:

Key Takeaways

Docker Compose Monitoring Stack: Set up Prometheus, Grafana, and a FastAPI application using Docker Compose, where Prometheus scrapes metrics every 15 seconds from the application's /metrics endpoint. Use volumes to load the prometheus.yml configuration file that tells Prometheus which endpoints to monitor.

Application Metrics Exposure: The FastAPI application exposes counter metrics (total HTTP requests), gauge metrics (virtual memory bytes), and histogram metrics (HTTP request duration buckets) at localhost:8000/metrics that Prometheus can understand and scrape.

Container Network Communication: While you access services via localhost:port from your machine, containers communicate using container names and ports within the Docker Compose network. Prometheus connects to the FastAPI app using fastapi-app:8000/metrics internally.

Grafana Configuration and Dashboards: Connect Grafana to Prometheus using prometheus:9090 as the data source URL, then import pre-built dashboards to visualize request rate, average response time, memory usage, and CPU usage of your application in real-time.