当前位置:   article > 正文

Prometheus监控Kafka集群_prometheus consul exporter监控多个kafka

prometheus consul exporter监控多个kafka

prometheus监控kafka常见的有两种开源方案,一种是传统的部署exporter的方式,一种是通过jmx配置监控,本文将采用第二种方式进行配置。

  • 项目地址:
    • kafka_exporter:https://github.com/danielqsj/kafka_exporter
    • jmx_exporter:https://github.com/prometheus/jmx_exporter

1、安装部署

现有kafka三节点的集群,环境大概如下:

主机组件
10.3.0.41–node1zookeeper,kafka
10.3.0.42–node2zookeeper,kafka
10.3.20.4–node3zookeeper,kafka

接着分别在如上三台主机上进行如下配置:

  1. wget https://raw.githubusercontent.com/prometheus/jmx_exporter/master/example_configs/kafka-2_0_0.yml
  2. wget https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.12.0/jmx_prometheus_javaagent-0.12.0.jar

分别创建统一的配置放置目录:

  1. mkdir -p /usr/local/kafka/jmx/
  2. mv kafka-2_0_0.yml /usr/local/kafka/jmx/kafka-2_0_0.yml
  3. mv jmx_prometheus_javaagent-0.12.0.jar /usr/local/kafka/jmx/jmx_prometheus_javaagent-0.12.0.jar

然后在启动的配置文件中添加如下两行:

  1. $ cat bin/kafka-server-start.sh
  2.  
  3. if [ $# -lt 1 ];
  4. then
  5. echo "USAGE: $0 [-daemon] server.properties [--override property=value]*"
  6. exit 1
  7. fi
  8. base_dir=$(dirname $0)
  9.  
  10. if [ "x$KAFKA_LOG4J_OPTS" = "x" ]; then
  11. export KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:$base_dir/../config/log4j.properties"
  12. fi
  13.  
  14. if [ "x$KAFKA_HEAP_OPTS" = "x" ]; then
  15. export KAFKA_HEAP_OPTS="-Xmx1G -Xms1G"
  16. fi
  17.  
  18. EXTRA_ARGS=${EXTRA_ARGS-'-name kafkaServer -loggc'}
  19.  
  20. #如下两行内容
  21. export JMX_PORT="9999"
  22. export KAFKA_OPTS="-javaagent:/usr/local/kafka/jmx/jmx_prometheus_javaagent-0.12.0.jar=9991:/usr/local/kafka/jmx/kafka-2_0_0.yml"
  23.  
  24. COMMAND=$1
  25. case $COMMAND in
  26. -daemon)
  27. EXTRA_ARGS="-daemon "$EXTRA_ARGS
  28. shift
  29. ;;
  30. *)
  31. ;;
  32. esac
  33.  
  34. exec $base_dir/kafka-run-class.sh $EXTRA_ARGS kafka.Kafka "$@"

然后重启kafka。

2,配置 prometheus.yml 添加监控目标

  1. $ vim /usr/local/prometheus/prometheus.yml
  2.  
  3. - job_name: 'kafka-cluster'
  4. scrape_interval: 5s
  5. static_configs:
  6. - targets: ['10.3.0.41:9991']
  7. - targets: ['10.3.0.42:9991']
  8. - targets: ['10.3.20.4:9991']

重启服务。

  1. $ systemctl restart prometheus

或者通过命令热加载:

  1. curl -XPOST localhost:9090/-/reload

5,配置 Grafana 的模板

展示模板通过ID进行导入,可用ID有:758910466,11963等等

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/678745
推荐阅读
相关标签
  

闽ICP备14008679号