使用jmx?exporter采集kafka指標(biāo)示例詳解
預(yù)置條件
安裝kafka、prometheus
使用JMX exporter暴露指標(biāo)
下載jmx exporter以及配置文件。Jmx exporter中包含了kafka各個組件的指標(biāo),如server metrics、producer metrics、consumer metrics等,但這些指標(biāo)并不是prometheus格式的,因此需要通過重命名方式轉(zhuǎn)變?yōu)閜rometheus格式,重命名規(guī)則配置在kafka-2_0_0.yml
中。
wget https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.12.0/jmx_prometheus_javaagent-0.12.0.jar wget https://raw.githubusercontent.com/prometheus/jmx_exporter/master/example_configs/kafka-2_0_0.yml
kafka集群啟用監(jiān)控
啟用的方式比較簡單,只需要在kafka-server-start.sh
中添加如下兩行即可:
... #添加如下兩行 export JMX_PORT="7081" export KAFKA_OPTS="-javaagent:/Users/charlie.liu/kafka_2.13-3.2.3/monitor/jmx_prometheus_javaagent-0.12.0.jar=7072:/Users/charlie.liu/kafka_2.13-3.2.3/monitor/kafka-2_0_0.yml" COMMAND=$1 case $COMMAND in -daemon) EXTRA_ARGS="-daemon "$EXTRA_ARGS shift ;; *) ;; esac exec $base_dir/kafka-run-class.sh $EXTRA_ARGS kafka.Kafka "$@"
prometheus的配置文件如下,啟動之后即可看到kafka的指標(biāo):
global: scrape_interval: 15s scrape_configs: - job_name: "kafka-cluster" static_configs: - targets: ["localhost:7072"]
采集producer/consumer的指標(biāo)
kafka的producer metrics和consumer metrics的格式與kafka server metrics的格式不同,因此需要特定的重命名配置,可以將其追加到kafka-2_0_0.yml
文件中:
# MBean: kafka.producer:type=producer-metrics,client-id=([-.w]+) - pattern: kafka.(.*)<type=(.*)-metrics, client-id=(.*)><>(.+):\w* name: kafka_$2-metrics labels: client_id: "$3" attr_name: "$4" help: "Kafka global client JMX metric $1 $2-metrics" type: GAUGE # MBean: kafka.producer:type=producer-node-metrics,client-id=([-.w]+),node-id=([0-9]+) # MBean: kafka.consumer:type=consumer-node-metrics,client-id=([-.w]+),node-id=([0-9]+) - pattern: kafka.(.*)<type=(.*)-metrics, client-id=(.*), node-id=(.*)><>(.+):\w* name: kafka_$2_$5-metrics labels: client_id: "$3" node_id: "$4" attr_name: "$5" help: "Kafka client JMX metric $1 $2-metrics" type: GAUGE - pattern: kafka.(.*)<type=(.*)-metrics, client-id=(.*), topic=(.*)><>(.+):\w* name: kafka_$2_$5-metrics labels: client_id: "$3" topic: "$4" attr_name: "$5" help: "Kafka client JMX metric $1 $2-metrics" type: GAUGE
使用如下方式啟動consumer,
KAFKA_OPTS="-javaagent:/kafka_2.13-3.2.3/monitor/jmx_prometheus_javaagent-0.12.0.jar=7073:/kafka_2.13-3.2.3/monitor/kafka-2_0_0.yml" kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic charlie-test1 --from-beginning
并在prometheus的配置文件中添加consumer target,reload prometheus 配置即可發(fā)現(xiàn)consumer的指標(biāo),producer的指標(biāo)采集與consumer類似。
global: scrape_interval: 15s scrape_configs: - job_name: "kafka-cluster" static_configs: - targets: ["localhost:7072"] - job_name: "kafka-consumer" static_configs: - targets: ["localhost:7073"]
官方給出了Jmx exporter的其他例子。
注:由于不同的配置Jmx exporter生成的kafka指標(biāo)名稱是不一樣的,因此并沒有統(tǒng)一的kafka grafana dashboard,最好還是自己繪制。
以上就是使用jmx exporter采集kafka指標(biāo)示例詳解的詳細(xì)內(nèi)容,更多關(guān)于jmx exporter采集kafka的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
SpringBoot?如何使用sharding?jdbc進(jìn)行分庫分表
這篇文章主要介紹了SpringBoot?如何使用sharding?jdbc進(jìn)行分庫分表,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-02-02java8列表中通過stream流根據(jù)對象屬性去重的三種方式
這篇文章主要介紹了java8列表中通過stream流根據(jù)對象屬性去重的三種方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-08-08java中Redisson的看門狗機(jī)制的實現(xiàn)
本文主要介紹了java中Redisson的看門狗機(jī)制的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-01-01Spring Security 強(qiáng)制退出指定用戶的方法
本篇文章主要介紹了Spring Security 強(qiáng)制退出指定用戶的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-03-03Mybatis不支持batchInsertOrUpdate返顯id問題
這篇文章主要介紹了Mybatis不支持batchInsertOrUpdate返顯id問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-05-05