Prometheus 监控分布式数据库集群的核心是通过标准化 Exporter 统一采集指标、多维标签打标、PromQL 聚合分析,并结合拓扑关系判断整体健康度;支持 MongoDB、CockroachDB、Redis Cluster 等多种数据库,无需依赖其主从或分片架构。
Prometheus 监控分布式数据库集群状态,核心在于把集群各节点的运行指标统一采集、打标、聚合,并结合拓扑关系识别整体健康度。它不依赖数据库自身是否“主从”或“分片”,而是通过标准化 Exporter + 多维标签 + PromQL 聚合实现跨节点可观测。
每个数据库节点需运行对应 Exporter,将内部状态转化为 HTTP 接口暴露的 Prometheus 格式指标:
mongodb_exporter,自动发现副本集成员,暴露 mongodb_mongod_replset_my_state(当前节点角色)、mongodb_mongod_replset_oplog_window(oplog 时间窗口)、mongodb_mongod_connections_current 等/health 和 /metrics 端点,无需额外 Exporter;关键指标如 crdb_sql_exec_queries_total、crdb_store_capacity_used_percent、crdb_node_liveness_status 可直接抓取redis_exporter 连接每个 Redis 实例,通过 redis_instance_role 标签区分 master/slave,再用 redis_cluster_nodes_count 和 redis_cluster_state 判断集群整体状态在 Kubernetes 环境中,避免硬编码 IP,改用声明式方式自动关联实例:
Service(ClusterIP 或 Headless),确保每个 Pod 有稳定 DNS 名称ServiceMonitor(配合 Prometheus Operator)或 PrometheusRule,按 label 匹配服务,例如:matchLabels: { app: "mongodb-replicaset" }
--web.listen-address=:9216 --mongodb.global-labels="cluster=prod,shard=shard0",让所有指标自带上下文标签
单看某个节点指标意义有限,必须升维到集群视角:
count by (cluster) (mongodb_mongod_replset_my_state{my_state="PRIMARY"} == 1) == 1 and count by (cluster) (mongodb_mongod_replset_my_state != 0) >= 3
——要求每个 cluster 恰好有 1 个 PRIMARY,且总存活节点 ≥ 3
count by (job) (crdb_node_liveness_status == 0) > 0
结合告警持续时间(如 for: 2m),避免瞬时抖动误报
min_over_time(redis_cluster_state[5m]) == 1
只要过去 5 分钟内任意时刻返回非 1,即触发异常
Grafana 面板不能只堆砌图表,要体现集群结构:
$cluster、$shard)实现下钻:先看集群整体延迟热力图 → 点击高延迟 shard → 查看该 shard 内各节点 CPU/网络/慢命令分布⚠️ {{ $values | printf "%.0f" }} nodes offline,让运维一眼识别风险规模
crdb_store_range_underreplicated_count > 0 时整行变红,提示数据冗余不足