天天看點

prometheus+pushgateway+grafana(監控可視化)+自定義監控

prometheus+grafana部署參考之前文檔:https://blog.51cto.com/jschu/3237358

pushgateway概述&部署

優勢:

prometheus 采用 pull 模式,可能由于不在一個子網或者防火牆原因,導緻 prometheus 無法直接拉取各個 target 資料。

在監控業務資料的時候,需要将不同資料彙總, 由 prometheus 統一收集。

弊端:

1.将多個節點資料彙總到 pushgateway, 如果 pushgateway 挂了,受影響比多個 target 大。

2.prometheus 拉取狀态 up 隻針對 pushgateway, 無法做到對每個節點有效。

3.pushgateway 可以持久化儲存所有push給它的所有監控資料,是以即使被監控伺服器已經下線,prometheus 還會拉取到舊的監控資料,需要手動清理。

使用docker安裝pushgateway

修改prometheus.yml檔案,隻配置一個pull拉取對象pushgateway,其他被監控伺服器都push到pushgateway上。

prometheus+pushgateway+grafana(監控可視化)+自定義監控

使用api方式push資料到pushgateway上

預設url位址格式為:http://<ip>:9091/metrics/job/<job_name>{/<label_name>/<label_value>},其中<job_name>是必填項,後面可以添加任意數量的 标簽對,一般會添加一個instance/<instance_name>執行個體名稱标簽來區分各個名額。

pushgateway ui頁面

prometheus+pushgateway+grafana(監控可視化)+自定義監控
prometheus+pushgateway+grafana(監控可視化)+自定義監控

添加honor_labels,避免監控資料的job、instance被pushgateway本身的job=pushgateway, instance=pushgateway覆寫。

監控資料寫入到檔案,再将檔案内容push到pushgateway

prometheus+pushgateway+grafana(監控可視化)+自定義監控

通過api方式delete删除某個或某一組的監控資料

grafana展示自定義的監控項

data source添加資料源,選擇prometheus

prometheus+pushgateway+grafana(監控可視化)+自定義監控

2.grafana建立dashboards

prometheus+pushgateway+grafana(監控可視化)+自定義監控

3.對新增的dashboard進行設定

prometheus+pushgateway+grafana(監控可視化)+自定義監控

4.填寫基本資訊,除了名稱、描述、還可以打上一些标簽:

prometheus+pushgateway+grafana(監控可視化)+自定義監控

5.建立一個變量

prometheus+pushgateway+grafana(監控可視化)+自定義監控

6.在設定變量的頁面進行設定,如下圖:

prometheus+pushgateway+grafana(監控可視化)+自定義監控

7.基本配置完成了,現在可以配置一個監控

prometheus+pushgateway+grafana(監控可視化)+自定義監控

8.建立一個graph

prometheus+pushgateway+grafana(監控可視化)+自定義監控
prometheus+pushgateway+grafana(監控可視化)+自定義監控

9.配置展示名稱

prometheus+pushgateway+grafana(監控可視化)+自定義監控

10.如下圖,選擇"metrics"頁,資料源選擇"prometheus",紅框3位置輸入内容"my_sample_counter_total{status=“success”, job="$job"}",頁面會立即展示my_sample_counter_total這個監控項的曲線圖:

prometheus+pushgateway+grafana(監控可視化)+自定義監控

11.自定義監控項展示成功了,點選右上角"儲存"

prometheus+pushgateway+grafana(監控可視化)+自定義監控

12.檢視新增的dashboard展示闆

prometheus+pushgateway+grafana(監控可視化)+自定義監控

13.如果您想将這個監控項的配置導出來,以便備份或者導入到另一個grafana系統,可以在設定頁面點選"json model"菜單,得到json格式的配置資訊,自行儲存,如下圖:

prometheus+pushgateway+grafana(監控可視化)+自定義監控