Zum Hauptinhalt springen
Zurück zur Kategorie

Server-Überwachungstools: Grafana, Prometheus und Netdata

Prometheus + Grafana Stack-Einrichtung, Netdata, node_exporter, Alarmregeln, Dashboard-Erstellung und Server-Metrik-Überwachung.

Lesezeit: 18 Min. Monitoring
monitoringgrafanaprometheusnetdataserverüberwachungalertdashboard

Inhaltsverzeichnis

Server-Überwachungstools: Grafana, Prometheus und Netdata

Die effektive Überwachung Ihrer Serverinfrastruktur ist entscheidend für die frühzeitige Erkennung von Leistungsproblemen und die Vermeidung von Ausfallzeiten. In dieser Anleitung richten wir ein umfassendes Server-Überwachungssystem mit Prometheus, Grafana und Netdata ein.

Was ist Prometheus?

Prometheus ist ein von der Cloud Native Computing Foundation (CNCF) unterstütztes Open-Source-System zur Metrikerfassung und Überwachung. Mit seiner Pull-basierten Architektur ruft es regelmäßig Metriken von Zielsystemen über HTTP ab und speichert sie in einer Zeitreihendatenbank.

Wichtige Funktionen von Prometheus:

  • PromQL: Leistungsstarke Abfragesprache zur Metrikanalyse
  • Pull-Based Model: Abruf von Metriken über HTTP
  • Service Discovery: Automatische Zielerkennung (Kubernetes, Consul, DNS)
  • Alert Manager: Bedingungsbasiertes Alarmmanagement
  • Multidimensionale Daten: Flexibles Label-basiertes Datenmodell
  • Federation: Hierarchische Verknüpfung mehrerer Prometheus-Server

Node Exporter Installation

Node Exporter ist ein Prometheus-Exporter, der Hardware- und Betriebssystem-Metriken von Linux-Servern sammelt.

Installation mit Systemd

hljs bash
# Node Exporter herunterladen
cd /tmp
curl -LO https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gz
tar xzf node_exporter-1.7.0.linux-amd64.tar.gz

# Binary verschieben
sudo mv node_exporter-1.7.0.linux-amd64/node_exporter /usr/local/bin/

# Benutzer erstellen
sudo useradd --no-create-home --shell /bin/false node_exporter

# Systemd-Servicedatei
sudo tee /etc/systemd/system/node_exporter.service > /dev/null <<EOF
[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target

[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter \\
  --collector.systemd \\
  --collector.processes \\
  --web.listen-address=:9100

[Install]
WantedBy=multi-user.target
EOF

# Service starten
sudo systemctl daemon-reload
sudo systemctl enable --now node_exporter
sudo systemctl status node_exporter

Node Exporter mit Docker

hljs yaml
# docker-compose.yml
version: '3.8'
services:
  node-exporter:
    image: prom/node-exporter:latest
    container_name: node-exporter
    restart: unless-stopped
    ports:
      - "9100:9100"
    volumes:
      - /proc:/host/proc:ro
      - /sys:/host/sys:ro
      - /:/rootfs:ro
    command:
      - '--path.procfs=/host/proc'
      - '--path.sysfs=/host/sys'
      - '--path.rootfs=/rootfs'
      - '--collector.filesystem.mount-points-exclude=^/(sys|proc|dev|host|etc)($$|/)'

Metriken überprüfen:

hljs bash
curl http://localhost:9100/metrics | head -50

Prometheus Installation

Prometheus Stack mit Docker Compose

hljs yaml
# docker-compose.yml
version: '3.8'
services:
  prometheus:
    image: prom/prometheus:latest
    container_name: prometheus
    restart: unless-stopped
    ports:
      - "9090:9090"
    volumes:
      - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
      - ./prometheus/alert_rules.yml:/etc/prometheus/alert_rules.yml
      - prometheus_data:/prometheus
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--storage.tsdb.path=/prometheus'
      - '--storage.tsdb.retention.time=30d'
      - '--web.enable-lifecycle'

volumes:
  prometheus_data:

Prometheus-Konfiguration

hljs yaml
# prometheus/prometheus.yml
global:
  scrape_interval: 15s
  evaluation_interval: 15s
  scrape_timeout: 10s

alerting:
  alertmanagers:
    - static_configs:
        - targets:
            - alertmanager:9093

rule_files:
  - "alert_rules.yml"

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']

  - job_name: 'node-exporter'
    static_configs:
      - targets:
          - 'node-exporter:9100'
          - '192.168.1.10:9100'
          - '192.168.1.11:9100'
        labels:
          env: 'production'

  - job_name: 'docker'
    static_configs:
      - targets: ['cadvisor:8080']

Alarmregeln

Erkennen Sie kritische Zustände mit Prometheus-Alarmregeln:

hljs yaml
# prometheus/alert_rules.yml
groups:
  - name: server_alerts
    rules:
      - alert: HoheCPUAuslastung
        expr: 100 - (avg by(instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100) > 85
        for: 5m
        labels:
          severity: warning
        annotations:
          summary: "Hohe CPU-Auslastung ({{ $labels.instance }})"
          description: "CPU-Auslastung beträgt {{ $value | printf \"%.1f\" }}% - seit 5 Minuten über 85%."

      - alert: HoherSpeicherverbrauch
        expr: (1 - (node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes)) * 100 > 90
        for: 5m
        labels:
          severity: critical
        annotations:
          summary: "Hoher Speicherverbrauch ({{ $labels.instance }})"
          description: "Speicherverbrauch beträgt {{ $value | printf \"%.1f\" }}% - über 90%."

      - alert: FestplatteFastVoll
        expr: (1 - (node_filesystem_avail_bytes{fstype!~"tmpfs|overlay"} / node_filesystem_size_bytes{fstype!~"tmpfs|overlay"})) * 100 > 85
        for: 10m
        labels:
          severity: warning
        annotations:
          summary: "Festplatte fast voll ({{ $labels.instance }})"
          description: "{{ $labels.mountpoint }} Festplattenauslastung beträgt {{ $value | printf \"%.1f\" }}%"

      - alert: InstanzNichtErreichbar
        expr: up == 0
        for: 2m
        labels:
          severity: critical
        annotations:
          summary: "Instanz nicht erreichbar ({{ $labels.instance }})"
          description: "{{ $labels.job }} Ziel ist seit 2 Minuten nicht erreichbar."

Alertmanager-Einrichtung

hljs yaml
# alertmanager/alertmanager.yml
global:
  resolve_timeout: 5m

route:
  group_by: ['alertname', 'severity']
  group_wait: 30s
  group_interval: 5m
  repeat_interval: 4h
  receiver: 'telegram'
  routes:
    - match:
        severity: critical
      receiver: 'telegram'
      repeat_interval: 1h

receivers:
  - name: 'telegram'
    telegram_configs:
      - bot_token: 'IHR_BOT_TOKEN'
        chat_id: IHRE_CHAT_ID
        parse_mode: 'HTML'
        message: |
          <b>{{ .Status | toUpper }}</b>
          <b>Alarm:</b> {{ .CommonLabels.alertname }}
          <b>Schweregrad:</b> {{ .CommonLabels.severity }}
          <b>Instanz:</b> {{ .CommonLabels.instance }}
          <b>Beschreibung:</b> {{ .CommonAnnotations.description }}

Grafana Installation

Grafana mit Docker Compose

hljs yaml
services:
  grafana:
    image: grafana/grafana:latest
    container_name: grafana
    restart: unless-stopped
    ports:
      - "3000:3000"
    volumes:
      - grafana_data:/var/lib/grafana
      - ./grafana/provisioning:/etc/grafana/provisioning
    environment:
      - GF_SECURITY_ADMIN_USER=admin
      - GF_SECURITY_ADMIN_PASSWORD=StarkesPasswort123!
      - GF_USERS_ALLOW_SIGN_UP=false
      - GF_SERVER_ROOT_URL=https://grafana.example.com

volumes:
  grafana_data:

Beliebte Grafana-Dashboards

Sie können fertige Dashboards von Grafana.com importieren:

# Node Exporter Full Dashboard
Dashboard ID: 1860
Datenquelle: Prometheus

# Docker Container Monitoring
Dashboard ID: 893

# Prometheus Stats
Dashboard ID: 2

Zum Importieren: Grafana → Dashboards → Import → Dashboard-ID eingeben → Load → Prometheus-Datenquelle auswählen → Import.

Benutzerdefinierte PromQL-Abfragen

hljs promql
# CPU-Auslastung in Prozent
100 - (avg by(instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)

# RAM-Auslastung in Prozent
(1 - (node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes)) * 100

# Festplattenauslastung in Prozent
(1 - (node_filesystem_avail_bytes{mountpoint="/"} / node_filesystem_size_bytes{mountpoint="/"})) * 100

# Netzwerkverkehr (Bytes/Sekunde)
rate(node_network_receive_bytes_total{device="eth0"}[5m])
rate(node_network_transmit_bytes_total{device="eth0"}[5m])

# System-Betriebszeit
node_time_seconds - node_boot_time_seconds

Netdata Installation

Netdata ist ein Echtzeit-Server-Überwachungstool. Die Installation ist äußerst einfach und liefert sofort detaillierte Metriken.

Ein-Befehl-Installation

hljs bash
# Automatisches Installationsskript
bash <(curl -Ss https://my-netdata.io/kickstart.sh)

# Nach der Installation
sudo systemctl status netdata

Weboberfläche: http://SERVER_IP:19999

Netdata mit Docker

hljs yaml
version: '3.8'
services:
  netdata:
    image: netdata/netdata:latest
    container_name: netdata
    restart: unless-stopped
    ports:
      - "19999:19999"
    cap_add:
      - SYS_PTRACE
      - SYS_ADMIN
    security_opt:
      - apparmor:unconfined
    volumes:
      - netdataconfig:/etc/netdata
      - netdatalib:/var/lib/netdata
      - netdatacache:/var/cache/netdata
      - /proc:/host/proc:ro
      - /sys:/host/sys:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro

volumes:
  netdataconfig:
  netdatalib:
  netdatacache:

Vollständiger Monitoring-Stack (Docker Compose)

Kombinieren Sie alle Komponenten in einer einzigen Compose-Datei:

hljs yaml
# docker-compose.monitoring.yml
version: '3.8'
services:
  prometheus:
    image: prom/prometheus:latest
    container_name: prometheus
    restart: unless-stopped
    ports:
      - "9090:9090"
    volumes:
      - ./prometheus:/etc/prometheus
      - prometheus_data:/prometheus
    networks:
      - monitoring

  grafana:
    image: grafana/grafana:latest
    container_name: grafana
    restart: unless-stopped
    ports:
      - "3000:3000"
    volumes:
      - grafana_data:/var/lib/grafana
    depends_on:
      - prometheus
    networks:
      - monitoring

  node-exporter:
    image: prom/node-exporter:latest
    container_name: node-exporter
    restart: unless-stopped
    ports:
      - "9100:9100"
    networks:
      - monitoring

  alertmanager:
    image: prom/alertmanager:latest
    container_name: alertmanager
    restart: unless-stopped
    ports:
      - "9093:9093"
    networks:
      - monitoring

networks:
  monitoring:
    driver: bridge

volumes:
  prometheus_data:
  grafana_data:
hljs bash
docker compose -f docker-compose.monitoring.yml up -d

Mit dem Prometheus + Grafana + Netdata Stack können Sie Ihre gesamte REXE-Serverinfrastruktur über ein einziges Dashboard überwachen. Alarmregeln ermöglichen die proaktive Erkennung von Problemen.