DevOps 監控與告警系統

DevOps 2025-01-02T09:00:00.000Z

DevOps 監控與告警系統

監控與告警是 DevOps 的核心能力,能即時發現問題並通知相關人員。

Prometheus 基礎

global:
  scrape_interval: 15s

scrape_configs:
  - job_name: "node"
    static_configs:
      - targets: ["localhost:9100"]

  - job_name: "myapp"
    static_configs:
      - targets: ["localhost:3000"]

PromQL 查詢範例

100 - (avg by(instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)
(1 - (node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes)) * 100
rate(http_requests_total{status=~"5.."}[5m]) / rate(http_requests_total[5m])

Alertmanager 設定

route:
  receiver: "slack-notifications"
  routes:
    - match:
        severity: critical
      receiver: "pagerduty"

receivers:
  - name: "slack-notifications"
    slack_configs:
      - api_url: "https://hooks.slack.com/..."
        channel: "#alerts"