Ceph 監控中應用 Prometheus 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 總能區分出來了吧,就像這樣:

不過 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. 參考文檔

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章