# Prometheus Alert Tracker with Grafana Visualization

This project creates a comprehensive system monitoring solution by combining Prometheus metrics collection with Grafana's powerful visualization capabilities. The system tracks vital server metrics, triggers alerts when thresholds are exceeded, and presents the data through interactive dashboards.
## Project Overview
I developed a Prometheus-based alert tracking system that exports system metrics to Grafana for creating complex, visually appealing visualizations. The solution combines:
- **Prometheus** for metrics collection and alert management
- **Python** with specialized libraries for metric exporting
- **Grafana** for advanced data visualization and dashboarding
## System Architecture
1. **Prometheus Server**: Collects and stores time-series metrics
2. **Python Exporter**: Custom exporter that gathers system metrics
3. **Grafana Server**: Visualizes data from Prometheus with interactive dashboards
## Implementation Details
### 1. Prometheus Installation
I installed Prometheus securely by creating a dedicated system user and group:
```bash
sudo useradd --no-create-home --shell /bin/false prometheus
sudo groupadd prometheus
sudo usermod -a -G prometheus prometheus
This security-focused approach ensures Prometheus runs with minimal privileges.
I developed a Python exporter (python_exporter.py
) that uses:
- psutil: For gathering system metrics
- prometheus-client: For exposing metrics in Prometheus format
Key metrics collected:
- CPU usage (per core and aggregate)
- Disk I/O (read/write operations, bytes)
- Network traffic (inbound/outbound)
- Memory utilization (used, cached, available)
- System load averages
Example exporter code snippet:
from prometheus_client import start_http_server, Gauge
import psutil
cpu_usage = Gauge('system_cpu_percent', 'Current CPU usage percent')
mem_usage = Gauge('system_memory_percent', 'Current memory usage percent')
def collect_metrics():
cpu_usage.set(psutil.cpu_percent())
mem_usage.set(psutil.virtual_memory().percent)
While Prometheus provides basic graphing capabilities, its visualization options are limited:
The native Prometheus graph shows raw metrics but lacks advanced visualization features
I configured Grafana to address Prometheus' visualization limitations by:
-
Creating Interactive Dashboards
- Developed comprehensive dashboards with multiple visualization types
- Implemented templating for flexible metric selection
- Added annotation support for event tracking
-
Setting Up Alerting
- Configured threshold-based alerts
- Integrated with notification channels (Email, Slack, etc.)
- Implemented alert escalation policies
- Real-time System Monitoring: Track all critical server metrics
- Beautiful Visualizations: Grafana's rich visualization library
- Custom Alerting: Get notified when metrics exceed thresholds
- Historical Analysis: Compare current performance with historical trends
- Exportable Dashboards: Share dashboards with team members
- Linux server (tested on Ubuntu 20.04)
- Python 3.8+
- Docker (for Grafana installation)
- Clone this repository
- Install Prometheus following the official guide
- Set up the Python exporter:
pip install -r requirements.txt python python_exporter.py
- Install Grafana:
docker run -d -p 3000:3000 --name=grafana grafana/grafana-enterprise
-
Configure Prometheus to scrape your Python exporter by editing
prometheus.yml
:scrape_configs: - job_name: 'python_exporter' static_configs: - targets: ['localhost:8000']
-
Set up Grafana:
- Login to
http://localhost:3000
(admin/admin) - Add Prometheus as data source (URL:
http://prometheus:9090
) - Import the sample dashboard from
dashboards/sample.json
- Login to
To configure alerts in Grafana:
- Navigate to Alert -> Notification channels
- Add your preferred channel (Email, Slack, etc.)
- Create alert rules in your dashboard panels
Example CPU alert rule:
avg_over_time(system_cpu_percent{instance="localhost:8000"}[5m]) > 80
This project is licensed under the MIT License - see the LICENSE file for details.
- Prometheus team for the excellent monitoring system
- Grafana Labs for their visualization tools
- psutil developers for the comprehensive system metrics library