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.
- Host: GitHub
- URL: https://github.com/rahuldongre-us/python-prometheus-grafana-docker
- Owner: rahuldongre-us
- License: mit
- Created: 2025-06-01T00:06:46.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-06-01T02:49:17.000Z (8 months ago)
- Last Synced: 2025-06-01T12:38:21.759Z (8 months ago)
- Topics: alert, checkov, fastapi, grafana, monitoring, observability, prometheus, python3, trivy
- Language: HCL
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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!
[](https://opensource.org/licenses/MIT)

[](https://github.com/rahuldongre-us/python-prometheus-grafana-docker/stargazers)
[](https://github.com/rahuldongre-us/python-prometheus-grafana-docker/issues)
[](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.