Prometheus 监控之 zookeeper

zookeeper 监控

git项目地址:https://github.com/jiankunking/zookeeper_exporter
exporter下载地址:https://github.com/carlpett/zookeeper_exporter/releases/download/v1.0.2/zookeeper_exporter

[sss@keeper01 ~]$ /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")
[sss@keeper01 ~]$ /usr/local/bin/zookeeper_exporter
[sss@keeper01 ~]$ 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 ...]

猜你喜欢

转载自blog.csdn.net/qq_25934401/article/details/84345905