Ceph 监控中应用 Prometheus relabel 功能

本文涉及的产品
可观测可视化 Grafana 版,10个用户账号 1个月
可观测监控 Prometheus 版,每月50GB免费额度
简介: 1. 问题描述工作环境中有三个独立的 Ceph 集群,分别负责对象存储、块存储和文件存储。搭建这几个 Ceph 集群时,我对 Ceph 重命名 Cluster name 的难度没有足够的了解,所以使用的都是默认的 cluster name:ceph,不巧的是 Prometheus 的 ceph_exporter 就是用 cluster name 来区分不同集群,结果是 Grafana 中各个集群的数据无法区分,所有的集群数据都绘制在了一个图标中,非常乱不说,而且部分数据还无法正常显示。

relabel

1. 问题描述

工作环境中有三个独立的 Ceph 集群,分别负责对象存储、块存储和文件存储。搭建这几个 Ceph 集群时,我对 Ceph 重命名 Cluster name 的难度没有足够的了解,所以使用的都是默认的 cluster name:ceph,不巧的是 Prometheus 的 ceph_exporter 就是用 cluster name 来区分不同集群,结果是 Grafana 中各个集群的数据无法区分,所有的集群数据都绘制在了一个图标中,非常乱不说,而且部分数据还无法正常显示。

也许大家会说,那就改 Ceph cluster name 不就好了。问题是 Ceph 修改 Cluster name 没那么简单,ceph 文件存储目录都是和 Cluster name 有对应关系的,所以很多配置文件和数据都需要修改目录才能生效,对于已经开始正式使用的 Ceph 集群,这么做风险有点大。当然如果给每个 Ceph 集群单独搭建一个 Prometheus 和 Grafana 环境的话,问题也能解决,但这种方式显得太没技术含量了,不到万不得已,实在不想采用。

我最开始想到的解决方式是修改 ceph_exporter,既然 cluster name 不行,那加上 Ceph 的 fsid 总能区分出来了吧,就像这样:

image.png

不过 fsid 这个变量很难直观看出来代表的是哪个 Ceph 集群,也不是一个好的方案。

最后多亏 neurodrone,才了解到 Prometheus 的 relabel 功能,可以完美的解决这个问题。

2. relabel 配置

Relabel 的本意其实修改导出 metrics 信息的 label 字段,可以对 metrics 做过滤,删除某些不必要的 metrics,label 重命名等,而且也支持对 label 的值作出修改。

举一个例子,三个集群的 ceph_pool_write_total 的 label cluster 取值都为 ceph。但在 Prometheus 的配置中,他们分别是分属于不通 job 的,我们可以通过对 job 进行 relabel 来修改 cluster label 的指,来完成区分。

# cluster1's metric
ceph_pool_write_total{cluster="ceph",pool=".rgw.root"} 4

# cluster2's metric
ceph_pool_write_total{cluster="ceph",pool=".rgw.root"} 10

# cluster3's metric
ceph_pool_write_total{cluster="ceph",pool=".rgw.root"} 7

具体的配置如下,cluster label 的值就改为了 ceph*,并且导出到了新 label clusters 中。

scrape_configs:
  - job_name: 'ceph1'
    relabel_configs:
    - source_labels: ["cluster"]
      replacement: "ceph1"
      action: replace
      target_label: "clusters"
    static_configs:
    - targets: ['ceph1:9128']
      labels:
        alias: ceph1

  - job_name: 'ceph2'
    relabel_configs:
    - source_labels: ["cluster"]
      replacement: "ceph2"
      action: replace
      target_label: "clusters"
    static_configs:
    - targets: ['ceph2:9128']
      labels:
        alias: ceph2

  - job_name: 'ceph3'
    relabel_configs:
    - source_labels: ["cluster"]
      replacement: "ceph3"
      action: replace
      target_label: "clusters"
    static_configs:
    - targets: ['ceph3:9128']
      labels:
        alias: ceph3

修改后的 metric 信息变成这个样子,这样我们就可以区分出不同的 Ceph 集群的数据了。

# cluster1's metric
ceph_pool_write_total{clusters="ceph1",pool=".rgw.root"} 4

# cluster2's metric
ceph_pool_write_total{clusters="ceph2",pool=".rgw.root"} 10

# cluster3's metric
ceph_pool_write_total{clusters="ceph3",pool=".rgw.root"} 7

3. Grafana dashboard 调整

光是修改 Prometheus 的配置还不够,毕竟我们还要在界面上能体现出来,Grafana 的 dashboard 也要做对应的修改,本文使用的 dashboard 是 Ceph - Cluster

首先是要 dashboard 添加 clusters 变量,在界面上操作即可。
先点击 dashboard 的 "settings" 按钮(显示齿轮图标的就是)

image.png

如下图所示添加 clusters variable,最后保存。

image.png

我们已经可以在 dashboard 上看到新加的 variable 了:

image.png

接下来每个图表的查询语句也要做对应的修改:

image.png

最终改好的 dashboard json 文件可从如下链接下载到:
ceph-cluster.json

4. 参考文档

目录
相关文章
|
5月前
|
Prometheus 监控 Cloud Native
云原生监控实战:Prometheus+Grafana快速搭建指南
云原生监控实战:Prometheus+Grafana快速搭建指南
|
5月前
|
存储 Prometheus 监控
OSS监控体系搭建:Prometheus+Grafana实时监控流量、错误码、存储量(开源方案替代云监控自定义视图)
本方案基于Prometheus构建OSS监控系统,涵盖架构设计、指标采集、可视化、告警及性能优化,助力企业实现高可用、低成本的自建监控体系。
587 1
|
6月前
|
Prometheus 监控 Cloud Native
除了Prometheus,还有哪些工具可以监控Docker Swarm集群的资源使用情况?
除了Prometheus,还有哪些工具可以监控Docker Swarm集群的资源使用情况?
536 79
|
5月前
|
存储 监控 Cloud Native
云原生监控实战:Prometheus+Grafana打造RDS多维度预警体系
本方案构建了基于Prometheus与Thanos的云原生RDS监控体系,涵盖数据采集、存储、可视化与告警全流程。支持10万+QPS采集、90%存储压缩,具备<30秒告警延迟能力。通过自定义指标与智能预警策略,显著提升故障发现效率,实现分钟级响应。
445 5
|
5月前
|
Prometheus 监控 Cloud Native
|
4月前
|
Prometheus 监控 Cloud Native
Docker 部署 Prometheus 和 Grafana 监控 Spring Boot 服务
Docker 部署 Prometheus 和 Grafana 监控 Spring Boot 服务实现步骤
525 0
|
8月前
|
Prometheus Kubernetes 监控
Kubernetes监控:Prometheus与AlertManager结合,配置邮件告警。
完成这些步骤之后,您就拥有了一个可以用邮件通知你的Kubernetes监控解决方案了。当然,所有的这些配置都需要相互照应,还要对你的Kubernetes集群状况有深入的了解。希望这份指南能帮助你创建出适合自己场景的监控系统,让你在首次发现问题时就能做出响应。
471 22
|
11月前
|
存储 数据采集 Prometheus
Grafana Prometheus Altermanager 监控系统
Grafana、Prometheus 和 Alertmanager 是一套强大的开源监控系统组合。Prometheus 负责数据采集与存储,Alertmanager 处理告警通知,Grafana 提供可视化界面。本文简要介绍了这套系统的安装配置流程,包括各组件的下载、安装、服务配置及开机自启设置,并提供了访问地址和重启命令。适用于希望快速搭建高效监控平台的用户。
614 20
|
11月前
|
Prometheus 监控 Cloud Native
Prometheus+Grafana监控Linux主机
通过本文的步骤,我们成功地在 Linux 主机上使用 Prometheus 和 Grafana 进行了监控配置。具体包括安装 Prometheus 和 Node Exporter,配置 Grafana 数据源,并导入预设的仪表盘来展示监控数据。通过这种方式,可以轻松实现对 Linux 主机的系统指标监控,帮助及时发现和处理潜在问题。
1001 7
|
11月前
|
Prometheus 监控 Cloud Native
无痛入门Prometheus:一个强大的开源监控和告警系统,如何快速安装和使用?
Prometheus 是一个完全开源的系统监控和告警工具包,受 Google 内部 BorgMon 系统启发,自2012年由前 Google 工程师在 SoundCloud 开发以来,已被众多公司采用。它拥有活跃的开发者和用户社区,现为独立开源项目,并于2016年加入云原生计算基金会(CNCF)。Prometheus 的主要特点包括多维数据模型、灵活的查询语言 PromQL、不依赖分布式存储、通过 HTTP 拉取时间序列数据等。其架构简单且功能强大,支持多种图形和仪表盘展示模式。安装和使用 Prometheus 非常简便,可以通过 Docker 快速部署,并与 Grafana 等可
5856 2