Ubuntu下Docker监控与告警的实现方案
docker run --rm -d --name=cadvisor -p 8080:8080 --volume=/:/rootfs:ro --volume=/var/run:/var/run:ro --volume=/sys:/sys:ro --volume=/var/lib/docker/:/var/lib/docker:ro google/cadvisor:latest)。prometheus.yml)。告警规则需结合指标阈值、持续时间、告警级别(warning/critical)设计,常见规则示例:
sum(rate(container_cpu_usage_seconds_total[5m])) by (instance) > 0.75(持续5分钟CPU使用率超过75%);container_memory_usage_bytes / container_spec_memory_limit_bytes > 0.9(内存使用率超过90%);container_fs_usage_bytes / container_fs_limit_bytes > 0.85(磁盘使用率超过85%);increase(docker_container_restart_count[1h]) > 3(1小时内重启次数超过3次)。alertmanager.yml):route:
group_by: ['alertname', 'container'] # 按告警名称、容器分组
group_wait: 30s # 等待30秒收集同一组告警
group_interval: 5m # 组内告警间隔5分钟
repeat_interval: 1h # 重复告警间隔1小时
receiver: 'slack-notifications' # 接收方名称
receivers:
- name: 'slack-notifications'
slack_configs:
- api_url: 'https://hooks.slack.com/services/your-webhook-url' # Slack Webhook URL
channel: '#docker-alerts' # Slack频道
title: '{{ .CommonAnnotations.summary }}' # 告警标题
text: '{{ .CommonAnnotations.description }}' # 告警详情