← Все статьи
Prometheus + Grafana: мониторинг с нуля
Архитектура стека
Prometheus скрейпит метрики по HTTP, хранит их в собственной time-series DB. Grafana подключается к Prometheus как источник данных и строит дашборды.
node_exporter → Prometheus → Grafana → Dashboard
↑
alerting rules → Alertmanager → Telegram
Разворачивание через Docker Compose
version: '3.8'
services:
prometheus:
image: prom/prometheus:latest
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
- prometheus_data:/prometheus
ports:
- "9090:9090"
grafana:
image: grafana/grafana:latest
volumes:
- grafana_data:/var/lib/grafana
ports:
- "3000:3000"
environment:
GF_SECURITY_ADMIN_PASSWORD: admin
node_exporter:
image: prom/node-exporter:latest
pid: host
volumes:
- /proc:/host/proc:ro
- /sys:/host/sys:ro
command:
- '--path.procfs=/host/proc'
- '--path.sysfs=/host/sys'
volumes:
prometheus_data:
grafana_data:
Конфигурация Prometheus
# prometheus.yml
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'node'
static_configs:
- targets: ['node_exporter:9100']
- job_name: 'caddy'
static_configs:
- targets: ['caddy:2019']
Примеры PromQL запросов
Загрузка CPU
100 - (avg(rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)
Использование памяти
(1 - node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes) * 100
Дисковое пространство
(1 - node_filesystem_avail_bytes{mountpoint="/"} / node_filesystem_size_bytes{mountpoint="/"}) * 100
Alerting rules
# alerts.yml
groups:
- name: host
rules:
- alert: HighCPU
expr: 100 - (avg(rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100) > 80
for: 5m
labels:
severity: warning
annotations:
summary: "Высокая загрузка CPU на {{ $labels.instance }}"
- alert: DiskSpaceLow
expr: (1 - node_filesystem_avail_bytes{mountpoint="/"} / node_filesystem_size_bytes{mountpoint="/"}) * 100 > 85
for: 10m
labels:
severity: critical
Настройка Grafana
- Откройте
http://localhost:3000 - Data Sources → Add → Prometheus → URL:
http://prometheus:9090 - Import дашборд
1860(Node Exporter Full) из templating.grafana.com
Дашборд 1860 — готовый набор из 200+ метрик для Linux-серверов. Импортируйте и настраивайте алерты под свои пороги.
Вывод
Стек Prometheus + Grafana — стандарт мониторинга. На за.hour времени получаете полную видимость инфраструктуры с алертами и историческими данными.