1. 程式人生 > >Prometheus 監控之 zookeeper

Prometheus 監控之 zookeeper

zookeeper 監控

git專案地址:https://github.com/jiankunking/zookeeper_exporter
exporter下載地址:https://github.com/carlpett/zookeeper_exporter/releases/download/v1.0.2/zookeeper_exporter

[[email protected] ~]$ /usr/local/bin/zookeeper_exporter --help
Usage of /usr/local/bin/zookeeper_exporter:
  -bind-addr string
        bind address for
the metrics server (default ":9141") -log-level string log level (default "info") -metrics-path string path to metrics endpoint (default "/metrics") -reset-on-scrape should a reset command be sent to zookeeper on each scrape (default true) -version show version and exit
-zookeeper string host:port for zookeeper socket (default "localhost:2181") [[email protected] ~]$ /usr/local/bin/zookeeper_exporter [[email protected] ~]$ curl localhost:9141/metrics # HELP go_gc_duration_seconds A summary of the GC invocation durations. # TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 3.1513e-05 go_gc_duration_seconds{quantile="0.25"} 4.2555e-05 go_gc_duration_seconds{quantile="0.5"} 4.9278e-05 go_gc_duration_seconds{quantile="0.75"} 8.2042e-05 go_gc_duration_seconds{quantile="1"} 0.000212331 go_gc_duration_seconds_sum 0.002286821 go_gc_duration_seconds_count 31 # HELP go_goroutines Number of goroutines that currently exist. # TYPE go_goroutines gauge go_goroutines 14 ……

ZooKeeper 提供了四字命令(The Four Letter Words),用來獲取 ZooKeeper 服務的當前狀態及相關資訊。

有哪些命令可以使用?

ZooKeeper四字命令	功能描述
conf	列印配置
cons	列出所有連線到這臺伺服器的客戶端全部連線/會話詳細資訊。包括"接受/傳送"的包數量、會話id、操作延遲、最後的操作執行等等資訊。
crst	重置所有連線的連線和會話統計資訊。
dump	列出那些比較重要的會話和臨時節點。這個命令只能在leader節點上有用。
envi	打印出服務環境的詳細資訊。
reqs	列出未經處理的請求
ruok	即"Are you ok",測試服務是否處於正確狀態。如果確實如此,那麼服務返回"imok",否則不做任何相應。
stat	輸出關於效能和連線的客戶端的列表。
srst	重置伺服器的統計。
srvr	列出連線伺服器的詳細資訊
wchs	列出伺服器watch的詳細資訊。
wchc	通過session列出伺服器watch的詳細資訊,它的輸出是一個與watch相關的會話的列表。
wchp	通過路徑列出伺服器watch的詳細資訊。它輸出一個與session相關的路徑。
mntr	輸出可用於檢測叢集健康狀態的變數列表

可以在客戶端可以通過 telnet 或 nc 向 ZooKeeper 提交相應的命令。舉個最常用的栗子:

echo mntr | nc ip 2181
指標名 解釋
指標名 解釋
zk_version 版本
zk_avg_latency 平均 響應延遲
zk_max_latency 最大 響應延遲
zk_min_latency 最小 響應延遲
zk_packets_received 收包數
zk_packets_sent 發包數
zk_num_alive_connections 活躍連線數
zk_outstanding_requests 堆積請求數
zk_server_state 主從狀態
zk_znode_count znode 數
zk_watch_count watch 數
zk_ephemerals_count 臨時節點數
zk_approximate_data_size 近似資料總和大小
zk_open_file_descriptor_count 開啟 檔案描述符 數
zk_max_file_descriptor_count 最大 檔案描述符 數
leader才有的指標
zk_followers Follower 數
zk_synced_followers 已同步的 Follower 數
zk_pending_syncs 阻塞中的 sync 操作
需要指定閾值的指標

zk_outstanding_requests 堆積請求數
zk_pending_syncs 阻塞中的 sync 操作
zk_avg_latency 平均 響應延遲
zk_open_file_descriptor_count 開啟 檔案描述符 數
zk_max_file_descriptor_count 最大 檔案描述符 數
zk_up 1
zk_server_state 主從狀態
zk_num_alive_connections 活躍連線數

rule檔案(僅供參考):
groups:
- name: zookeeperStatsAlert 
  rules:
  - alert: 堆積請求數過大
    expr: avg(zk_outstanding_requests) by (instance) > 10 
    for: 1m
    labels:
      severity: critical
    annotations:
      summary: "Instance {{ $labels.instance }} "
      description: "積請求數過大"
  - alert: 阻塞中的 sync 過多
    expr: avg(zk_pending_syncs) by (instance) > 10 
    for: 1m
    labels:
      severity: critical
    annotations:
      summary: "Instance {{ $labels.instance }} " 
      description: "塞中的 sync 過多"
  - alert: 平均響應延遲過高
    expr: avg(zk_avg_latency) by (instance) > 10
    for: 1m
    labels:
      severity: critical
    annotations:
      summary: "Instance {{ $labels.instance }} "
      description: '平均響應延遲過高'
  - alert: 開啟檔案描述符數大於系統設定的大小
    expr: zk_open_file_descriptor_count > zk_max_file_descriptor_count * 0.85
    for: 1m
    labels:
      severity: critical
    annotations:
      summary: "Instance {{ $labels.instance }} "
      description: '開啟檔案描述符數大於系統設定的大小'
  - alert: zookeeper伺服器宕機
    expr: zk_up == 0
    for: 1m
    labels:
      severity: critical
    annotations:
      summary: "Instance {{ $labels.instance }} "
      description: 'zookeeper伺服器宕機'
  - alert: zk主節點丟失
    expr: absent(zk_server_state{state="leader"})  != 1 
    for: 1m
    labels:
      severity: critical
    annotations:
      summary: "Instance {{ $labels.instance }} "
      description: 'zk主節點丟失'
Grafana畫圖:

在Grafana分享了zk監控圖:搜尋Zookeeper Exporer Overview 或者 拷貝pid 9236
在這裡插入圖片描述

kafka 監控

git專案地址:https://github.com/danielqsj/kafka_exporter
下載地址: https://github.com/danielqsj/kafka_exporter/releases/download/v1.2.0/kafka_exporter-1.2.0.linux-amd64.tar.gz

啟動

kafka_exporter --kafka.server=kafka:9092 [--kafka.server=another-server ...]