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

https://github.com/tyronejosee/prototype_metrics

Prototype for a complete Grafana and Prometheus monitoring setup, orchestrated with Docker Compose for easy deployment and configuration.
https://github.com/tyronejosee/prototype_metrics

docker-compose grafana json metrics prometheus python yaml

Last synced: 3 months ago
JSON representation

Prototype for a complete Grafana and Prometheus monitoring setup, orchestrated with Docker Compose for easy deployment and configuration.

Awesome Lists containing this project

README

          

# Prototype Metrics

Complete Grafana + Prometheus monitoring setup with Docker Compose, designed for learning and experimentation.

![Main](image.jpg)
![Dashboard](dashboard.webp)

## ๐Ÿ—๏ธ Architecture Overview

- **Grafana**: Web interface for creating dashboards and visualizing metrics
- **Prometheus**: Time-series database that stores metrics
- **Pushgateway**: Allows batch jobs to push metrics to Prometheus
- **Python Script**: Generates realistic system metrics

## ๐Ÿš€ Quick Start Guide

Prerequisites

- Docker and Docker Compose installed
- Python 3.7+ (for the metric generator script)

Start the Services

```bash
# Start all services in the background
docker compose up -d

# Check if all services are running
docker compose ps
```

Install Python Dependencies

> Recommended to use [uv](https://docs.astral.sh/uv/guides/install-python/#getting-started).

```bash
uv sync
```

Run the Metric Generator

```bash
uv run metric_generator.py
```

Access the Services

- **Grafana**:
- Username: `admin`
- Password: `admin123`

- **Prometheus**:
- **Pushgateway**:

## ๐Ÿ“Š Pre-configured Dashboard

The setup includes a pre-configured dashboard called "System Metrics Dashboard" that displays:

- CPU Usage
- Memory Usage
- Request Count
- Error Count

## ๐Ÿ› ๏ธ Customization Ideas

Adding New Metrics

1. Modify `metric_generator.py` to include new metrics
2. Update the dashboard JSON or create new panels in Grafana UI

Different Data Sources

- Replace Prometheus with InfluxDB for different time-series storage
- Add Loki for log aggregation
- Include Node Exporter for real system metrics

Advanced Features

- Set up alerting rules in Prometheus
- Add notification channels in Grafana
- Create custom alert conditions

## ๐Ÿงช Testing and Development

View Raw Metrics

Visit to see raw metrics from Pushgateway

Query Metrics in Prometheus

Go to and try these queries:

- `cpu_usage_percent`
- `memory_usage_percent`
- `rate(request_count_total[5m])`

Stop Everything

```bash
docker-compose down

# Remove volumes (caution: this deletes all data)
docker-compose down -v
```

## ๐Ÿ“ File Structure

```bash
prototype_grafana_prometheus/
โ”œโ”€โ”€ docker-compose.yml # Main orchestration file
โ”œโ”€โ”€ prometheus/
โ”‚ โ””โ”€โ”€ prometheus.yml # Prometheus configuration
โ”œโ”€โ”€ datasources/
โ”‚ โ””โ”€โ”€ prometheus.yml # Grafana datasource config
โ”œโ”€โ”€ dashboards/
โ”‚ โ”œโ”€โ”€ dashboard.yml # Dashboard provider config
โ”‚ โ””โ”€โ”€ system-metrics.json # Pre-built dashboard
โ”œโ”€โ”€ metric_generator.py # Metric generation script
โ”œโ”€โ”€ requirements.txt # Python dependencies
โ””โ”€โ”€ README.md # This file
```

## ๐Ÿ”ง Troubleshooting

Services won't start

- Check Docker is running: `docker ps`
- Check logs: `docker-compose logs [service-name]`

No data in Grafana

- Verify Prometheus is scraping:
- Check if metrics are being pushed:
- Ensure the Python script is running without errors

Can't access Grafana

- Wait a few minutes for services to fully start
- Check if port 3000 is available: `netstat -an | grep 3000`

## โš–๏ธ License

This project is licensed under the [MIT License](LICENSE).

Enjoy! ๐ŸŽ‰