首页
/ Dockprom监控实战:如何快速配置CPU、内存、存储告警规则

Dockprom监控实战:如何快速配置CPU、内存、存储告警规则

2026-01-19 11:24:04作者:冯爽妲Honey

Dockprom是一个Docker化的监控栈集合,通过Prometheus、Grafana、Alertmanager等组件,为Docker环境提供完整的监控解决方案。本文将详细介绍如何配置CPU、内存和存储的告警规则,帮助您快速搭建企业级的监控系统。

🔍 Dockprom监控架构概览

Dockprom监控系统包含多个核心组件:

  • Prometheus:作为指标数据库,负责收集和存储监控数据
  • Grafana:提供可视化仪表盘,直观展示监控指标
  • Alertmanager:管理告警通知,支持多种通知渠道
  • NodeExporter:收集主机级别的系统指标
  • cAdvisor:专门收集容器级别的资源使用情况

⚙️ 告警规则配置详解

主机级别CPU告警配置

prometheus/alert.rules文件中,您可以找到CPU负载告警的配置:

- alert: high_cpu_load
  expr: node_load1 > 1.5
  for: 30s
  labels:
    severity: warning
  annotations:
    summary: "Server under high load"
    description: "Docker host is under high load, the avg load 1m is at {{ $value}}. Reported by instance {{ $labels.instance }} of job {{ $labels.job }}."

这个规则会在CPU 1分钟平均负载超过1.5并持续30秒时触发告警。您可以根据服务器的CPU核心数调整阈值,一般建议设置为CPU核心数的70%-80%。

Docker主机CPU监控

内存使用率告警设置

内存告警规则监控系统内存使用情况:

- alert: high_memory_load
  expr: (sum(node_memory_MemTotal_bytes) - sum(node_memory_MemFree_bytes + node_memory_Buffers_bytes + node_memory_Cached_bytes) ) / sum(node_memory_MemTotal_bytes) * 100 > 85
  for: 30s
  labels:
    severity: warning
  annotations:
    summary: "Server memory is almost full"
    description: "Docker host memory usage is {{ humanize $value}}%. Reported by instance {{ $labels.instance }} of job {{ $labels.job }}."

此规则会在内存使用率达到85%并持续30秒时发出警告。

存储空间告警配置

存储告警确保您及时了解磁盘空间不足的问题:

- alert: high_storage_load
  expr: (node_filesystem_size_bytes{fstype="aufs"} - node_filesystem_free_bytes{fstype="aufs"}) / node_filesystem_size_bytes{fstype="aufs"}  * 100 > 85
  for: 30s
  labels:
    severity: warning
  annotations:
    summary: "Server storage is almost full"
    description: "Docker host storage usage is {{ humanize $value}}%. Reported by instance {{ $labels.instance }} of job {{ $labels.job }}."

重要提示:根据您的文件系统类型,需要修改fstype参数。例如,对于BTRFS系统,应将aufs改为btrfs

Docker容器内存监控

🎯 容器级别精细化监控

Jenkins容器告警示例

Dockprom还提供了针对特定容器的精细化监控:

- alert: jenkins_high_cpu
  expr: sum(rate(container_cpu_usage_seconds_total{name="jenkins"}[1m])) / count(node_cpu_seconds_total{mode="system"}) * 100 > 10
  for: 30s
  labels:
    severity: warning
  annotations:
    summary: "Jenkins high CPU usage"
    description: "Jenkins CPU usage is {{ humanize $value}}%."

这个规则监控Jenkins容器是否使用超过10%的总CPU资源。

容器内存使用告警

- alert: jenkins_high_memory
  expr: sum(container_memory_usage_bytes{name="jenkins"}) > 1200000000
  for: 30s
  labels:
    severity: warning
  annotations:
    summary: "Jenkins high memory usage"
    description: "Jenkins memory consumption is at {{ humanize $value}}."

当Jenkins容器内存使用超过1.2GB时触发告警。

Prometheus服务监控

🚀 快速部署指南

一键启动监控系统

git clone https://gitcode.com/gh_mirrors/do/dockprom
cd dockprom

ADMIN_USER='admin' ADMIN_PASSWORD='admin' ADMIN_PASSWORD_HASH='$2a$14$1l.IozJx7xQRVmlkEQ32OeEEfP5mRxTpbDTCTcXRqn19gXD8YK1pO' docker-compose up -d

📊 监控面板使用技巧

Docker主机监控面板

访问http://<host-ip>:3000使用admin/admin登录后,您将看到:

  • 系统运行时间CPU空闲百分比
  • 内存使用分布图(已用、空闲、缓冲区、缓存)
  • IO使用率图网络使用率图

容器监控面板

容器级别监控提供:

  • 各容器CPU使用率趋势图
  • 容器内存占用对比
  • 网络输入输出监控

💡 最佳实践建议

  1. 阈值调整:根据您的服务器配置调整告警阈值
  2. 文件系统适配:确保存储监控规则中的fstype与您的系统匹配
  3. 通知渠道配置:在alertmanager/config.yml中配置Slack、邮件等通知方式

通过Dockprom的告警规则配置,您可以轻松实现对企业级Docker环境的全面监控,确保系统稳定运行。

登录后查看全文
热门项目推荐
相关项目推荐