Monitoring muss nicht kompliziert sein. Prometheus + Grafana in 15 Minuten.
Docker Compose¶
services:
prometheus:
image: prom/prometheus:latest
ports: [“9090:9090”]
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
grafana:
image: grafana/grafana:latest
ports: [“3000:3000”]
environment:
GF_SECURITY_ADMIN_PASSWORD: admin
Prometheus-Konfiguration¶
prometheus.yml¶
global:
scrape_interval: 15s
scrape_configs:
- job_name: app
static_configs:
- targets: [“app:8080”]
Node.js-Metriken¶
import { collectDefaultMetrics, register } from ‘prom-client’;
collectDefaultMetrics();
app.get(‘/metrics’, async (req, res) => {
res.set(‘Content-Type’, register.contentType);
res.end(await register.metrics());
});
Grafana-Dashboards¶
Importieren Sie fertige Dashboards von grafana.com – ID 1860 (Node Exporter Full), ID 11159 (Node.js).
Alerting¶
prometheus rules¶
groups:
- name: alerts
rules:
- alert: HighErrorRate
expr: rate(http_errors_total[5m]) > 0.1
for: 5m
Ergebnis¶
15 Minuten und Sie haben Metriken, Grafiken und Alerting. Erweitern Sie schrittweise um weitere Exporter.