Prometheus 监控 Ceph 全栈实战:从 OSD 心跳到 RGW 请求的分布式存储可观测性
Prometheus 监控 Ceph 全栈实战:从 OSD 心跳到 RGW 请求的分布式存储可观测性
Ceph 作为软件定义存储的王者,支撑着无数云平台的块、文件、对象存储。然而,其复杂的组件(OSD、MON、MDS、RGW)和分布式一致性要求,使得集群健康状态、OSD 降级/慢请求、PG 状态异常、容量水位等问题若未被及时发现,可能导致数据丢失或业务中断。自 Mimic 版本起,Ceph 在 Manager 中原生内置了 Prometheus 导出模块,能够将集群的详细指标以标准格式暴露。本文将带你从启用模块、配置抓取到关键告警,构建一套覆盖全组件的 Ceph 可观测性体系。
1. 为什么选择内置 Prometheus 模块?
| 方案 | 说明 |
|---|---|
| ceph-mgr prometheus 模块(推荐) | 自 Ceph Mimic (13.x) 起内置,无需额外进程;指标丰富,持续更新;支持集群健康、OSD、MON、PG、RGW、NFS 等 |
| 独立 ceph-exporter | 第三方实现,适用于老版本 Ceph(0.80+),指标有限且维护滞后 |
强烈建议使用内置模块,本文将以 Ceph Pacific (16.x) / Quincy (17.x) / Reef (18.x) 为准,覆盖常见组件。
2. 启用并配置 Ceph Prometheus 模块
在任一 Ceph 管理节点上执行:
ceph mgr moduleenableprometheus ceph mgr modulels|grepprometheus# 确认已加载默认情况下,模块会在 Manager 的9283端口上暴露/metrics端点。验证:
curlhttp://<mgr-ip>:9283/metrics|head-20输出应包含ceph_health_status、ceph_osd_up等指标。
可选配置:如果你需要调整监听地址或端口,可在 Manager 配置中修改:
ceph configsetmgr mgr/prometheus/server_addr0.0.0.0 ceph configsetmgr mgr/prometheus/server_port9283如需收集 RGW 指标,需在 RGW 实例配置中添加rgw enable usage log = true,并启用rgw租户统计,然后重启 RGW。自 Pacific 版本起,prometheus 模块会自动抓取 RGW 指标(需 mgr 有访问 RGW admin 的权限)。
3. 配置 Prometheus 抓取
在prometheus.yml中添加:
scrape_configs:-job_name:'ceph'scrape_interval:30sstatic_configs:-targets:-'ceph-mgr1:9283'-'ceph-mgr2:9283'# 高可用 Manager,两个节点都暴露相同数据labels:cluster:'ceph-prod'注意:无论几个 mgr 实例,一次只需抓取一个(或两个但
instance标签相同),因为它们报告相同的集群状态。可配置成多 target 但保留一个活跃,以实现高可用抓取。
4. 核心监控指标与 PromQL
Ceph Prometheus 模块导出的指标命名以ceph_为前缀,标签包括cluster、osd、pool、instance等。
4.1 集群健康状态
| 指标 | 含义 |
|---|---|
ceph_health_status | 0=HEALTH_OK, 1=HEALTH_WARN, 2=HEALTH_ERR |
ceph_health_detail | 健康警告/错误的描述性标签(字符串,不易直接查询) |
PromQL 告警:ceph_health_status > 0表示非健康。
4.2 OSD 状态
| 指标 | 含义 |
|---|---|
ceph_osd_up | 每个 OSD 是否在线(1=up, 0=down) |
ceph_osd_in | 是否在集群中(1=in, 0=out) |
ceph_osd_nearfull | 接近满的 OSD 数量(从 Pacific 起可用) |
ceph_osd_full | 满的 OSD 数量 |
ceph_osd_stat_bytes_used/ceph_osd_stat_bytes_total | OSD 已用/总容量 |
PromQL:
- 离线 OSD:
ceph_osd_up == 0 - 全满 OSD:
ceph_osd_full > 0 - OSD 使用率:
ceph_osd_stat_bytes_used / ceph_osd_stat_bytes_total * 100
4.3 Placement Group (PG) 状态
| 指标 | 含义 |
|---|---|
ceph_pg_active | 活跃 PG 总数 |
ceph_pg_clean | 清洁 PG 总数 |
ceph_pg_degraded | 降级 PG 总数 |
ceph_pg_stuck_degraded | 卡在降级状态的 PG 数 |
ceph_pg_stuck_unclean | 卡在不洁状态的 PG 数 |
关键告警:ceph_pg_degraded > 0或ceph_pg_stuck_unclean > 0。
4.4 MON 状态
| 指标 | 含义 |
|---|---|
ceph_mon_quorum_status | 当前 MON 节点是否在法定数中(1=是) |
ceph_mon_num_elections | 选举次数(频繁选举表明不稳定) |
告警:ceph_mon_quorum_status == 0表示某 MON 节点已出法定数。
4.5 集群容量与池使用
| 指标 | 含义 |
|---|---|
ceph_cluster_total_bytes | 集群总物理容量 |
ceph_cluster_total_used_bytes | 已用物理容量 |
ceph_cluster_total_avail_bytes | 可用空间 |
ceph_pool_bytes_used/ceph_pool_max_avail | 池级别的使用和可用 |
PromQL:
- 集群使用率:
ceph_cluster_total_used_bytes / ceph_cluster_total_bytes * 100 - 池使用率:
ceph_pool_bytes_used / (ceph_pool_bytes_used + ceph_pool_max_avail) * 100
4.6 性能指标(I/O 与延迟)
| 指标 | 含义 |
|---|---|
ceph_osd_op_w_latency_sum/_count | OSD 写操作延迟 |
ceph_osd_op_r_latency_sum/_count | OSD 读操作延迟 |
ceph_osd_perf_apply_latency_seconds | 事务应用延迟 |
ceph_osd_perf_commit_latency_seconds | 提交延迟 |
ceph_pool_rd_bytes/ceph_pool_wr_bytes | 池级读写速率 |
PromQL:
- 平均写延迟:
rate(ceph_osd_op_w_latency_sum[5m]) / rate(ceph_osd_op_w_latency_count[5m]) - 池吞吐(MB/s):
rate(ceph_pool_wr_bytes[1m]) / 1024 / 1024
4.7 RGW 对象网关(若启用)
| 指标 | 含义 |
|---|---|
ceph_rgw_http_requests_total | RGW 请求总数 |
ceph_rgw_http_errors_total | RGW 错误数 |
ceph_rgw_qlen | 请求队列长度 |
ceph_rgw_cache_hit_total/_miss_total | 缓存命中/未命中 |
告警:rate(ceph_rgw_http_errors_total[5m]) > 0
5. Grafana 仪表盘推荐
Ceph 社区提供了非常成熟的官方仪表盘:
- Ceph Cluster Dashboard:ID2842(最经典),涵盖集群健康、OSD、PG、容量、MON、I/O 延迟、池统计等,完美适配 Prometheus 内置模块。
- Ceph RGW:ID13286,若使用 RGW,可独立导入。
- Ceph Pacific/Quincy Enhancements:ID15328,包含新版本增加的 nearfull、recovery 速率等面板。
导入后选择 Prometheus 数据源,将变量cluster绑定至你的 Ceph 集群标签。
6. 告警规则实战
groups:-name:ceph_alertsrules:-alert:CephClusterHealthWarnexpr:ceph_health_status == 1for:5mlabels:severity:warningannotations:summary:"Ceph 集群状态为 HEALTH_WARN"-alert:CephClusterHealthErrexpr:ceph_health_status == 2for:1mlabels:severity:criticalannotations:summary:"Ceph 集群状态为 HEALTH_ERR,立即处理!"-alert:CephOSDDownexpr:ceph_osd_up == 0for:5mlabels:severity:criticalannotations:summary:"OSD {{ $labels.osd }} 已离线"-alert:CephOSDHostDownexpr:ceph_osd_in == 0 and ceph_osd_up == 0for:1mlabels:severity:criticalannotations:summary:"OSD {{ $labels.osd }} 不在集群中且离线"-alert:CephOSDNearFullexpr:ceph_osd_nearfull>0for:10mlabels:severity:warningannotations:summary:"存在接近满的 OSD,立即添加容量或调整权重"-alert:CephPGsDegradedexpr:ceph_pg_degraded>0for:10mlabels:severity:warningannotations:summary:"PG 出现降级,数量:{{ $value }}"-alert:CephPGsStuckUncleanexpr:ceph_pg_stuck_unclean>0for:15mlabels:severity:criticalannotations:summary:"有 PG 长时间卡在不洁状态,数据可能不可访问"-alert:CephMonQuorumLostexpr:ceph_mon_quorum_status == 0for:1mlabels:severity:criticalannotations:summary:"MON 节点 {{ $labels.instance }} 失去法定数"-alert:CephClusterCapacityFullexpr:ceph_cluster_total_used_bytes / ceph_cluster_total_bytes * 100>85for:10mlabels:severity:warningannotations:summary:"Ceph 集群容量使用率超过 85%"-alert:CephPoolFullexpr:ceph_pool_bytes_used / (ceph_pool_bytes_used + ceph_pool_max_avail) * 100>85for:10mlabels:severity:warningannotations:summary:"池 {{ $labels.pool }} 使用率超过 85%"7. 进阶:多集群、安全与性能
7.1 多 Ceph 集群监控
为每个集群的 mgr 配置不同的cluster标签,在 Prometheus 中通过labels区分。Grafana 仪表盘通过变量cluster切换,轻松实现多集群统一监控。
7.2 安全加固
- Ceph Prometheus 端点默认无认证,建议通过防火墙限制仅 Prometheus 服务器可访问 9283 端口。
- 也可将 mgr 的 9283 绑定到
127.0.0.1,再用反向代理(如 Caddy/Nginx)添加 TLS 和 Basic Auth。 - 确保 mgr 具备读取 RGW 统计的权限(如
ceph dashboard set-rgw-api-access-key等),否则 RGW 指标会缺失。
7.3 性能影响
Prometheus 模块采集频率由 Prometheus scrape_interval 控制,mgr 本身每次抓取时会查询集群状态,对 mgr CPU 开销极小。通常 30s 抓取足够。
8. 总结
通过 Ceph 内置的 Prometheus 模块,你的分布式存储集群不再是一块模糊的黑洞。从集群健康灯、OSD 在线状态、PG 降级到 RGW 请求延迟,所有信息都转化为可查询、可告警的时序指标。结合 Grafana 丰富的仪表盘和 Alertmanager 的即时通知,你能在数据丢失风险萌芽时就采取行动,让 Ceph 真正成为软件定义存储的可观测基石。部署它,让存储层也能像应用一样被“看见”。
