Architecture
Exporter → Prometheus (storage) → Grafana (visualization)
↓
Alertmanager (alert routing)
Docker Compose Deployment
version: '3.8'
services:
prometheus:
image: prom/prometheus:v2.52.0
ports: ["9090:9090"]
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
- ./rules:/etc/prometheus/rules
- prom_data:/prometheus
command:
- '--storage.tsdb.retention.time=30d'
restart: unless-stopped
grafana:
image: grafana/grafana:10.4.2
ports: ["3000:3000"]
volumes: [grafana_data:/var/lib/grafana]
restart: unless-stopped
alertmanager:
image: prom/alertmanager:v0.27.0
ports: ["9093:9093"]
volumes: [./alertmanager.yml:/etc/alertmanager/config.yml]
restart: unless-stopped
node-exporter:
image: prom/node-exporter:v1.8.1
ports: ["9100:9100"]
restart: unless-stopped
volumes:
prom_data:
grafana_data:
Core Configuration
# prometheus.yml
global:
scrape_interval: 15s
evaluation_interval: 15s
rule_files:
- "rules/*.yml"
alerting:
alertmanagers:
- static_configs:
- targets: ['alertmanager:9093']
scrape_configs:
- job_name: 'node'
static_configs:
- targets: ['node-exporter:9100']
Common PromQL
# CPU usage
100 - (avg(rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)
# Memory usage
(node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes) / node_memory_MemTotal_bytes * 100
# Disk usage
(node_filesystem_size_bytes - node_filesystem_avail_bytes) / node_filesystem_size_bytes * 100
Alert Rule Example
groups:
- name: host-alerts
rules:
- alert: HighCPU
expr: 100 - (avg(rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100) > 80
for: 5m
labels:
severity: warning
annotations:
summary: "High CPU usage ({{ $labels.instance }})"
Recommended Grafana Dashboards
| Dashboard | ID | Description |
|---|---|---|
| Node Exporter Full | 1860 | Host resource monitoring |
| Prometheus Stats | 3662 | Prometheus self-monitoring |
Summary
The Prometheus ecosystem provides a complete monitoring solution. Setup is just the first step — the key is defining proper SLI metrics and reasonable alert thresholds.