最具影响力的数字化技术在线社区

168主编 发表于 2020-3-30 13:35:04

Kafka监控工具汇总

对于大数据集群来说,监控功能是非常必要的,通过日志判断故障低效,我们需要完整的指标来帮我们管理Kafka集群。本文讨论Kafka的监控以及一些常用的第三方监控工具。一、Kafka Monitoring首先介绍kafka的监控原理,第三方工具也是通过这些来进行监控的,我们也可以自己去是实现监控,官网关于监控的文档地址如下:http://kafka.apache.org/documentation/#monitoring](http://kafka.apache.org/documentation/#monitoring)kafka使用Yammer Metrics进行监控,Yammer Metrics是一个java的监控库。kafka默认有很多的监控指标,默认都使用JMX接口远程访问,具体方法是在启动broker和clients之前设置JMX_PORT:JMX_PORT=9997 bin/kafka-server-start.sh config/server.propertiesKafka的每个监控指标都是以JMX MBEAN的形式定义的,MBEAN是一个被管理的资源实例。我们可以使用Jconsole (Java Monitoring and Management Console),一种基于JMX的可视化监视、管理工具。来可视化监控的结果:https://img2018.cnblogs.com/blog/1089984/201908/1089984-20190823114818875-1697441762.jpg图2 Jconsole随后在Mbean下可以找到各种kafka的指标。Mbean的命名规范是 kafka.xxx:type=xxx,xxx=xxx主要分为以下几类:(监控指标较多,这里只截取部分,具体请查看官方文档)Graphing and Alerting 监控:kafka.server为服务器相关,kafka.network为网络相关。
DescriptionMbean nameNormal value
Message in ratekafka.server:type=BrokerTopicMetrics,name=MessagesInPerSec
Byte in rate from clientskafka.server:type=BrokerTopicMetrics,name=BytesInPerSec
Byte in rate from other brokerskafka.server:type=BrokerTopicMetrics,name=ReplicationBytesInPerSec
Request ratekafka.network:type=RequestMetrics,name=RequestsPerSec,request={Produce|FetchConsumer|FetchFollower}
Error ratekafka.network:type=RequestMetrics,name=ErrorsPerSec,request=([-.\w]+),error=([-.\w]+)Number of errors in responses counted per-request-type, per-error-code. If a response contains multiple errors, all are counted. error=NONE indicates successful responses.
Common monitoring metrics for producer/consumer/connect/streams监控:kafka运行过程中的监控。
Metric/Attribute nameDescriptionMbean name
connection-close-rateConnections closed per second in the window.kafka.:type=-metrics,client-id=([-.\w]+)
connection-close-totalTotal connections closed in the window.kafka.:type=-metrics,client-id=([-.\w]+)
Common Per-broker metrics for producer/consumer/connect/streams监控:每一个broker的监控。
Metric/Attribute nameDescriptionMbean name
outgoing-byte-rateThe average number of outgoing bytes sent per second for a node.kafka.:type=-node-metrics,client-id=([-.\w]+),node-id=(+)
outgoing-byte-totalThe total number of outgoing bytes sent for a node.kafka.:type=-node-metrics,client-id=([-.\w]+),node-id=(+)
Producer监控:producer调用过程中的监控。
Metric/Attribute nameDescriptionMbean name
waiting-threadsThe number of user threads blocked waiting for buffer memory to enqueue their records.kafka.producer:type=producer-metrics,client-id=([-.\w]+)
buffer-total-bytesThe maximum amount of buffer memory the client can use (whether or not it is currently used).kafka.producer:type=producer-metrics,client-id=([-.\w]+)
buffer-available-bytesThe total amount of buffer memory that is not being used (either unallocated or in the free list).kafka.producer:type=producer-metrics,client-id=([-.\w]+)
bufferpool-wait-timeThe fraction of time an appender waits for space allocation.kafka.producer:type=producer-metrics,client-id=([-.\w]+)
Consumer监控:consumer调用过程中的监控。
Metric/Attribute nameDescriptionMbean name
commit-latency-avgThe average time taken for a commit requestkafka.consumer:type=consumer-coordinator-metrics,client-id=([-.\w]+)
commit-latency-maxThe max time taken for a commit requestkafka.consumer:type=consumer-coordinator-metrics,client-id=([-.\w]+)
commit-rateThe number of commit calls per secondkafka.consumer:type=consumer-coordinator-metrics,client-id=([-.\w]+)
commit-totalThe total number of commit callskafka.consumer:type=consumer-coordinator-metrics,client-id=([-.\w]+)
Connect监控:
Attribute nameDescription
connector-countThe number of connectors run in this worker.
connector-startup-attempts-totalThe total number of connector startups that this worker has attempted.
Streams 监控:
Metric/Attribute nameDescriptionMbean name
commit-latency-avgThe average execution time in ms for committing, across all running tasks of this thread.kafka.streams:type=stream-metrics,client-id=([-.\w]+)
commit-latency-maxThe maximum execution time in ms for committing across all running tasks of this thread.kafka.streams:type=stream-metrics,client-id=([-.\w]+)
poll-latency-avgThe average execution time in ms for polling, across all running tasks of this thread.kafka.streams:type=stream-metrics,client-id=([-.\w]+)
这些指标涵盖了我们使用kafka过程中的各种情况,还有kafka.log记录日志信息。每一个Mbean下都有具体的参数。通过这些参数,比如出站进站速率,ISR变化速率,Producer端的batch大小,线程数,Consumer端的延时大小,流速等等,当然我们也要关注JVM,还有OS层面的监控,这些都有通用的工具,这里不做赘述。kafka的监控原理已经基本了解,其他第三方监控工具也大部分是在这个层面进行的完善,下面来介绍几款主流的监控工具。二、JmxToolJmxTool并不是一个框架,而是Kafka默认提供的一个工具,用于实时查看JMX监控指标。。打开终端进入到Kafka安装目录下,输入命令bin/kafka-run-class.sh kafka.tools.JmxTool便可以得到JmxTool工具的帮助信息。比如我们要监控入站速率,可以输入命令:bin/kafka-run-class.sh kafka.tools.JmxTool --object-name kafka.server:type=BrokerTopicMetrics,name=BytesInPerSec --jmx-url service:jmx:rmi:///jndi/rmi://:9997/jmxrmi --date-format "YYYY-MM-dd HH:mm:ss" --attributes FifteenMinuteRate --reporting-interval 5000BytesInPerSec的值每5秒会打印在控制台上:>kafka_2.12-2.0.0 rrd$ bin/kafka-run-class.sh kafka.tools.JmxTool --object-name kafka.server:type=BrokerTopicMetrics,name=BytesInPerSec --jmx-url service:jmx:rmi:///jndi/rmi://:9997/jmxrmi --date-format "YYYY-MM-dd HH:mm:ss" --attributes FifteenMinuteRate --reporting-interval 5000

Trying to connect to JMX url: service:jmx:rmi:///jndi/rmi://:9997/jmxrmi.

"time","kafka.server:type=BrokerTopicMetrics,name=BytesInPerSec:FifteenMinuteRate"

2018-08-10 14:52:15,784224.2587058166

2018-08-10 14:52:20,1003401.2319497257

2018-08-10 14:52:25,1125080.6160773218

2018-08-10 14:52:30,1593394.1860063889三、Kafka-Manager雅虎公司2015年开源的kafka监控框架,使用scala编写。github地址如下:https://github.com/yahoo/kafka-manager使用条件:
[*]Kafka 0.8.. or 0.9.. or 0.10.. or 0.11..
[*]Java 8+
下载kafka-manager配置:conf/application.confkafka-manager.zkhosts="my.zookeeper.host.com:2181,other.zookeeper.host.com:2181"部署:这里要用到sbt部署./sbt clean dist启动: bin/kafka-manager
指定端口:
$ bin/kafka-manager -Dconfig.file=/path/to/application.conf -Dhttp.port=8080
权限:
$ bin/kafka-manager -Djava.security.auth.login.config=/path/to/my-jaas.conf随后访问local host:8080就可以看到监控页面了:https://img2018.cnblogs.com/blog/1089984/201908/1089984-20190823114819193-337681804.jpg图 topichttps://img2018.cnblogs.com/blog/1089984/201908/1089984-20190823114819726-1560936510.jpg图 broker页面非常的简洁,也有很多丰富的功能,开源免费,推荐使用,只是目前版本支持到Kafka 0.8.. or 0.9.. or 0.10.. or 0.11,需要特别注意。四、kafka-monitorlinkin开源的kafka监控框架,github地址如下:https://github.com/linkedin/kafka-monitor基于 Gradle 2.0以上版本,支持java 7和java 8.支持kafka从0.8-2.0,用户可根据需求下载不同分支即可。使用:编译:$ git clone https://github.com/linkedin/kafka-monitor.git$ cd kafka-monitor $ ./gradlew jar修改配置:config/kafka-monitor.properties"zookeeper.connect" = "localhost:2181"启动:$ ./bin/kafka-monitor-start.sh config/kafka-monitor.properties
单集群启动:
$ ./bin/single-cluster-monitor.sh --topic test --broker-list localhost:9092 --zookeeper localhost:2181
多集群启动:
$ ./bin/kafka-monitor-start.sh config/multi-cluster-monitor.properties随后访问localhost:8080 看到监控页面https://img2018.cnblogs.com/blog/1089984/201908/1089984-20190823114820231-1617128097.jpg图 kafkamonitor同时我们还可以通过http请求查询其他指标:curl localhost:8778/jolokia/read/kmf.services:type=produce-service,name=*/produce-availability-avg总体来说,他的web功能比较简单,用户使用不多,http功能很有用,支持版本较多。五、Kafka Offset Monitor官网地址http://quantifind.github.io/KafkaOffsetMonitor/github地址 https://github.com/quantifind/KafkaOffsetMonitor使用:下载以后执行java -cp KafkaOffsetMonitor-assembly-0.3.0.jar:kafka-offset-monitor-another-db-reporter.jar \
   com.quantifind.kafka.offsetapp.OffsetGetterWeb \
   --zk zk-server1,zk-server2 \
   --port 8080 \
   --refresh 10.seconds \
   --retain 2.days
   --pluginsArgs anotherDbHost=host1,anotherDbPort=555随后查看localhost:8080https://img2018.cnblogs.com/blog/1089984/201908/1089984-20190823114820640-83468700.jpg图 offsetmonitor1https://img2018.cnblogs.com/blog/1089984/201908/1089984-20190823114821187-1920868912.jpg图offsetmonitor2这个项目更关注于对offset的监控,页面很丰富,但是15年以后不再更新,无法支持最新版本kafka。继续维护的版本地址如下https://github.com/Morningstar/kafka-offset-monitor。六、Cruise-controllinkin于2017年8月开源了cruise-control框架,用于监控大规模集群,包括一系列的运维功能,据称在linkedin有着两万多台的kafka集群,项目还在持续更新中。项目github地址:https://github.com/linkedin/cruise-control使用:下载
git clone https://github.com/linkedin/cruise-control.git && cd cruise-control/
编译
./gradlew jar
修改 config/cruisecontrol.properties
bootstrap.servers   zookeeper.connect
启动:
./gradlew jar copyDependantLibs
./kafka-cruise-control-start.sh [-jars PATH_TO_YOUR_JAR_1,PATH_TO_YOUR_JAR_2] config/cruisecontrol.properties 启动后访问:http://localhost:9090/kafkacruisecontrol/state没有页面,所有都是用rest api的形式提供的。接口列表如下:https://github.com/linkedin/cruise-control/wiki/REST-APIs这个框架灵活性很大,用户可以根据自己的情况来获取各种指标优化自己的集群。七、DoctorkafkaDoctorKafka是Pinterest 开源 Kafka 集群自愈和工作负载均衡工具。Pinterest 是一个进行图片分享的社交站点。他们使用 Kafka 作为中心化的消息传输工具,用于数据摄取、流处理等场景。随着用户数量的增加,Kafka 集群也越来越庞大,对它的管理日趋复杂,并变成了运维团队的沉重负担,因此他们研发了 Kafka 集群自愈和工作负载均衡工具 DoctorKafka,最近他们已经在GitHub 上将该项目开源。使用:下载:
git clone doctorkafka
cd doctorkafka
编译:
mvn package -pl kafkastats -am
启动:
java -server \
    -Dlog4j.configurationFile=file:./log4j2.xml \
    -cp lib/*:kafkastats-0.2.4.8.jar \
    com.pinterest.doctorkafka.stats.KafkaStatsMain \
      -broker 127.0.0.1 \
      -jmxport 9999 \
      -topic brokerstats \
      -zookeeper zookeeper001:2181/cluster1 \
      -uptimeinseconds 3600 \
      -pollingintervalinseconds 60 \
      -ostrichport 2051 \
      -tsdhostport localhost:18126 \
      -kafka_config /etc/kafka/server.properties \
      -producer_config /etc/kafka/producer.properties \
      -primary_network_ifacename eth0页面如下:https://img2018.cnblogs.com/blog/1089984/201908/1089984-20190823114822489-327716624.jpg图dockerkafkaDoctorKafka 在启动之后,会阶段性地检查每个集群的状态。当探测到 broker 出现故障时,它会将故障 broker 的工作负载转移给有足够带宽的 broker。如果在集群中没有足够的资源进行重分配的话,它会发出告警。属于一个自动维护集群健康的框架。八、BurrowBurrow是LinkedIn开源的一款专门监控consumer lag的框架。github地址如下:https://github.com/linkedin/Burrow使用Burrow监控kafka, 不需要预先设置lag的阈值, 他完全是基于消费过程的动态评估Burrow支持读取kafka topic和,zookeeper两种方式的offset,对于新老版本kafka都可以很好支持Burrow支持http, email类型的报警Burrow默认只提供HTTP接口(HTTP endpoint),数据为json格式,没有web UI。安装使用:$ Clone github.com/linkedin/Burrow to a directory outside of $GOPATH. Alternatively, you can export GO111MODULE=on to enable Go module.
$ cd to the source directory.
$ go mod tidy
$ go install示例:列出所有监控的Kafka集群
curl -s http://localhost:8000/v3/kafka |jq
{
"error": false,
"message": "cluster list returned",
"clusters": [
    "kafka",
    "kafka"
],
"request": {
    "url": "/v3/kafka",
    "host": "kafka"
}
}其他的框架,还有kafka-web-console:https://github.com/claudemamo/kafka-web-consolekafkat:https://github.com/airbnb/kafkatcapillary:https://github.com/keenlabs/capillarychaperone:https://github.com/uber/chaperone还有很多,但是我们要结合自己的kafka版本情况进行选择。作者:独孤风来源:https://www.cnblogs.com/tree1123/p/11399130.html
页: [1]
查看完整版本: Kafka监控工具汇总