天天看點

【大資料運維監控】Prometheus 内置的一些 Metrics

在使用 Prometheus 的時候,我們總會遇到 Prometheus 自身的監控名額,有些名額是需要結合到這些 名額來進行分析的嗎,這裡簡單的收集點 Prometheus 的自身的名額。

運作時的狀态

Prometheus 是一個 Go 開發的程式,自然是包含了 Go 的一些基礎名額,在 Prometheus 中,常見的 Go 的名額有:

  • go_goroutines
  • go_memstats_heap_alloc_bytes
  • go_memstats_heap_released_bytes

這些 metric 主要是在定位 prometheus 運作過程中記憶體或者 CPU 占用高的時候會比較有用,但是說實話,我用的不多,以為真的洩漏的時候,看這些 metric 還是不夠的,需要結合 pprof 進行。

規則運作狀态

在一個成熟的監控系統中,可能會設定很多不同的規則,但是,執行這些規則都是需要耗費系統資源的,是以,當有一些意外情況的時候,下面這些 metric 可能就能幫助上了:

  • prometheus_rule_evaluation_duration_seconds:所有的 rules(recording/alerting) 的計算的時間(分位值),這個可以用來分析規則是否過于複雜以及系統的狀态是否繁忙
  • prometheus_rule_evaluation_duration_seconds_count:執行所有的 rules 的累積時長,沒怎麼用到
  • prometheus_rule_group_duration_seconds:具體的 rule group 的耗時
  • prometheus_rule_group_interval_seconds:具體的 rule group 的執行間隔(如果沒有異常,應該和配置中的一緻,如果不一緻了,那很可能系統負載比較高)
  • prometheus_rule_group_iterations_missed_total:因為系統繁忙導緻被忽略的 rule 執行數量
  • prometheus_rule_group_last_duration_seconds:最後一次的執行耗時

采集狀态

這是一個比較重要的狀态,例如我經常關心的是 prometheus 采集 exporter 是否正确,是否真的采集到了資料還是說 exporter 逾時之類的異常,那麼都是通過這個類别的 metric 來定位的。

這個類别的 metric 其實就 5 個,分别是:

  • up:對應的 scrape target 是否是健康的,0 表示不線上(采集失敗了),1 表示正常
  • scrape_duration_seconds:采集這個 scrape target 花費的時間,這個可以用來定位 timeout
  • scrape_samples_post_metric_relabeling:在 metric 被 relabel 之後,還剩下的 sample 數量,關于 relabel 可以檢視我的另外一篇文章。
  • scrape_samples_scraped:scrape target 暴露出來的 sample 數量
  • scrape_series_added:在 2.10 添加的新 metric,表示這個 scrape target 新增加的系列數

存儲狀态

在 Prometheus 中,用的是自己的存儲引擎,并且它會進行記憶體緩存。是以,當發現查詢資料不對或者記憶體占用偏高的時候,最後不妨懷疑一下是不是存儲的問題,下面是一些可能有價值的資料:

  • prometheus_tsdb_blocks_loaded:目前已經加載到記憶體中的塊數量
  • prometheus_tsdb_compactions_triggered_total:壓縮操作被觸發的次數(可能很多,但不是每次出發都會執行)
  • prometheus_tsdb_compactions_total:啟動到目前位置壓縮的次數(預設是 2 小時一次)
  • prometheus_tsdb_compactions_failed_total:壓縮失敗的次數
  • prometheus_tsdb_head_chunks:head 中存放的 chunk 數量
  • prometheus_tsdb_head_chunks_created_total:head 中建立的 chunks 數量
  • prometheus_tsdb_head_chunks_removed_total:head 中移除的 chunks 數量
  • prometheus_tsdb_head_gc_duration_seconds:head gc 的耗時(分位值)
  • prometheus_tsdb_head_max_time:head 中的有效資料的最大時間(這個比較有價值)
  • prometheus_tsdb_head_min_time:head 中的有效資料的最小時間(這個比較有價值)
  • prometheus_tsdb_head_samples_appended_total:head 中添加的 samples 的總數(可以看增長速度)
  • prometheus_tsdb_head_series:head 中儲存的 series 數量
  • prometheus_tsdb_reloads_total:rsdb 被重新加載的次數

繼續閱讀