An open API service indexing awesome lists of open source software.

https://github.com/rahuldongre-us/python-prometheus-grafana-docker

Easily monitor your Python applications like a pro using Prometheus, Grafana, and Docker โ€“ all in one streamlined setup. This project offers a plug-and-play observability stack to track key metrics, set up alerting, and visualize real-time performance dashboards for your Python services.
https://github.com/rahuldongre-us/python-prometheus-grafana-docker

alert checkov fastapi grafana monitoring observability prometheus python3 trivy

Last synced: 3 months ago
JSON representation

Easily monitor your Python applications like a pro using Prometheus, Grafana, and Docker โ€“ all in one streamlined setup. This project offers a plug-and-play observability stack to track key metrics, set up alerting, and visualize real-time performance dashboards for your Python services.

Awesome Lists containing this project

README

          

# ๐Ÿš€ Python + Prometheus + Grafana Monitoring Stack (Dockerized)

Monitor your Python applications in real-time with a production-ready monitoring stack using **Prometheus**, **Grafana** and **Docker**. This repository helps developers and DevOps engineers bootstrap observability for microservices or monoliths with minimal setup. Checkov uses a common command line interface to manage and analyze infrastructure as code (IaC) scan results across platforms such as Terraform and other framework. Trivy to find vulnerabilities (CVE) & misconfigurations (IaC) across code repositories, binary artifacts, container images and more. All in one tool!

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
![Docker Compose](https://img.shields.io/badge/Docker--Compose-Ready-blue)
[![Stars](https://img.shields.io/github/stars/rahuldongre-us/python-prometheus-grafana-docker?style=social)](https://github.com/rahuldongre-us/python-prometheus-grafana-docker/stargazers)
[![Issues](https://img.shields.io/github/issues/rahuldongre-us/python-prometheus-grafana-docker)](https://github.com/rahuldongre-us/python-prometheus-grafana-docker/issues)
[![Last Commit](https://img.shields.io/github/last-commit/rahuldongre-us/python-prometheus-grafana-docker)](https://github.com/rahuldongre-us/python-prometheus-grafana-docker/commits/main)

---

## ๐Ÿ“Š Features

โœ… Easy setup with Docker Compose
โœ… Python app exposing metrics with `prometheus_client`
โœ… Pre-configured Prometheus scrape targets
โœ… Grafana ready for dashboards
โœ… Modular and extensible for production use

---

## โš™๏ธ Quick Start

### Prerequisites

- Docker & Docker Compose installed
- Python 3.7+ (optional, for local testing)

### Clone the Repository

```bash
git clone https://github.com/rahuldongre-us/python-prometheus-grafana-docker.git
cd python-prometheus-grafana-docker
docker-compose up --build -d
```

or

Start the application.

``` bash
chmod +x infra.sh
./infra.sh
```
Local docker should expose python app, prometheus and grafana.

Destroy the application.

``` bash
chmod +x cleanup-infra.sh
./cleanup-infra.sh
```

Scan for misconfiguration, CVE and other vulnerabilities.

``` bash
chmod +x scan.sh
./scan.sh
```
Splunk and email notification can be setup based on scan results at build time.

| Service | URL | Notes |
| ---------- | -------------------------------------------------------------- | -------------------------------- |
| Grafana | [http://localhost:3000](http://localhost:3000) | Default login: `admin` / `admin` |
| Prometheus | [http://localhost:9090](http://localhost:9090) | Live metrics & targets |
| Python App | [http://localhost:8000/metrics](http://localhost:8000/metrics) | Prometheus metrics endpoint |

---

๐Ÿ› ๏ธ Customize & Extend

Add More Metrics

Edit app/main.py and add custom Prometheus metrics using prometheus_client:

from prometheus_client import Counter

REQUESTS = Counter('http_requests_total', 'Total HTTP Requests')

Add More Services
Just define new services in docker-compose.yml and update prometheus.yml to scrape their metrics.

---
## Checkov

pip install checkov

docker run --rm -v $(pwd):/tf bridgecrew/checkov --directory /tf

### For Terraform files
checkov -d .

### For Dockerfiles
checkov --dockerfile-path ./app/Dockerfile

### Terraform & Dockerfile

docker run --rm -v $(pwd):/tf bridgecrew/checkov --directory /tf

docker run --rm -v $(pwd)/app/Dockerfile:/Dockerfile bridgecrew/checkov --dockerfile-path /Dockerfile

---
## Trivy

brew install aquasecurity/trivy/trivy

docker run --rm -v $(pwd):/project aquasec/trivy config /project

trivy config .

### Example: scan Python app image built by Terraform

trivy image python_app

---

๐Ÿ“Œ Use Cases

๐Ÿ“Š Monitoring microservices

โš™๏ธ System observability in Dev/Test environments

๐Ÿšจ Alerting integration with Prometheus AlertManager

๐Ÿงช Teaching/promoting observability best practices

---

๐Ÿง  Resources

[Prometheus Docs ](https://prometheus.io/docs/)

[Grafana Docs](https://grafana.com/docs/)

[Prometheus Python Client](https://github.com/prometheus/client_python)

[Checkov](https://www.checkov.io/)

[Trivy](https://trivy.dev/latest/)

---

๐Ÿ™Œ Acknowledgments

Built with โค๏ธ by Rahul Dongre
Inspired by open-source observability stacks worldwide.