Skip to content

Runbook: Server Metrics Collection

Přehled

Lightweight monitoring serverů bez Grafana/Prometheus. Agent na každém serveru sbírá metriky (CPU, RAM, disk, load) a posílá na sentinel collector. Historie 7 dní v SQLite.

Architektura

[server] agent.sh (cron */1) → POST /metrics/collect → [sentinel] collector.py → SQLite
                                                          /metrics/api/* → status page

Komponenty

Collector (sentinel)

  • Script: /opt/metrics/collector.py
  • Service: s60-metrics.service (systemd)
  • Port: 127.0.0.1:9100 (nginx proxy na /metrics/)
  • DB: /opt/metrics/metrics.db (SQLite, 7 dní retence)
  • API key: s60-metrics-2026-collector

Agent (každý server)

  • Script: /opt/metrics/agent.sh
  • Cron: */1 * * * *
  • Sbírá: CPU%, RAM%, Disk%, Load 1/5/15, Swap%, Network bytes

API endpointy

  • GET /metrics/api/metrics/current — aktuální metriky všech serverů
  • GET /metrics/api/metrics/history/<host> — 24h historie (5min buckety)
  • GET /metrics/api/metrics/hosts — seznam hostů
  • POST /metrics/collect — příjem metrik (API key required)

Správa

# Stav collectoru
systemctl status s60-metrics

# Restart
systemctl restart s60-metrics

# Logy
journalctl -u s60-metrics -f

# Ruční test agenta
bash /opt/metrics/agent.sh

# Kontrola dat
curl -s http://127.0.0.1:9100/api/metrics/current | python3 -m json.tool

# Přidat nový server
scp /opt/metrics/agent.sh root@<IP>:/opt/metrics/agent.sh
ssh root@<IP> "chmod +x /opt/metrics/agent.sh && (crontab -l 2>/dev/null | grep -v metrics/agent; echo '*/1 * * * * /opt/metrics/agent.sh') | crontab -"

Nasazené servery

Server Tailscale IP Stav
sentinel 100.112.158.91
prod-alfa 100.78.87.88
hub-alfa 100.68.138.14
cerebro 100.72.164.58
cortex 100.120.98.59
argus 100.110.6.46
fess 100.112.207.104

Prahy alertů

Metrika Warn Critical
CPU >60% >80%
RAM >70% >85%
Disk >70% >85%

Status page

Metriky se zobrazují na sentinel.studio60.cz/status/ v sekci "Servery" s mini sparkline grafem (CPU historie 6h).