当前位置:   article > 正文

kafka集群监控(kafka_exporter&prometheus&Grafana)_kafka_exporter 监控集群

kafka_exporter 监控集群

为了更直观的展示kafka实时消息生产速率以及某一topic下group_id与当前kafka之间的消息积压情况,采用kafka_exporter,promehues,grafana将相关指标实时展示

1. 下载 kafka_exporter(所在机器需与kafka集群网络相通)

wget https://github.com/danielqsj/kafka_exporter/releases/download/v1.2.0/kafka_exporter-1.2.0.linux-amd64.tar.gz

解压:  tar -zxvf kafka_exporter-1.2.0.linux-amd64.tar.gz 

切到相应目录:   cd kafka_exporter-1.2.0.linux-amd64

 ./kafka_exporter --kafka.server=kafkaIP或者域名:9092 & (只需填写kafka集群的一个ip即可

对应的服务端口为9308

2.下载prometheus 

 wget https://github.com/prometheus/prometheus/releases/download/v2.15.1/prometheus-2.15.1.linux-amd64.tar.gz

解压  

tar -zxvf prometheus-2.15.1.linux-amd64.tar.gz

 prometheus.yml为promethues配置文件,可以先启动验证服务可用性

 

 cd ./prometheus-2.15.1.linux-amd64

prometheus.yml 这个文件是对应的配置文件,在未添加kafka_exporter之前可以先启动查看下服务是否正常

  1. # my global config
  2. global:
  3. scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  4. # evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  5. # scrape_timeout is set to the global default (10s).
  6. # Alertmanager configuration
  7. #alerting:
  8. # alertmanagers:
  9. # - static_configs:
  10. # - targets:
  11. # - alertmanager:9093
  12. # Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
  13. rule_files:
  14. # - "first_rules.yml"
  15. # - "second_rules.yml"
  16. # A scrape configuration containing exactly one endpoint to scrape:
  17. # Here it's Prometheus itself.
  18. scrape_configs:
  19. # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  20. - job_name: 'prometheus'
  21. # metrics_path defaults to '/metrics'
  22. # scheme defaults to 'http'.
  23. static_configs:
  24. - targets: ['localhost:9090']

运行prometheus

 ./prometheus --config.file=prometheus.yml

ip:9090即可打开其web页面

将kafka_exporter对应的服务添加进preomethues(添加在配置文件后面就行

  1. static_configs:
  2. - targets: ['localhost:9090']
  3. - job_name: 'vpc_md_kafka'
  4. static_configs:
  5. - targets: ['localhost:9308']

重新启动promethues(后台运行)

nohup ./prometheus --config.file=prometheus.yml 2>&1 &

在status里的targets看到服务正常,下面就是使用grafana将监控指标可视化

 

3. 下载grafana

wget https://dl.grafana.com/oss/release/grafana-6.5.2-1.x86_64.rpm

 root用户下执行

yum localinstall grafana-6.5.2-1.x86_64.rpm

启动grafana

  1. service grafana-server start #启动
  2. service grafana-server status #查看状态

打开grafana的web页面  ip:3000,添加promethues数据源

导入监控图标,对于grafana的监控,官方有监控图标,不需要自己搞

鼠标离开7589的框就会跳转到下一步

官方的监控界面是这样的,我这儿是测试华景,所以没什么数据

可以自己写查询满足需求,生产环境的监控界面弄的也比较简单,三个图标

生产环境的监控环境配置及对应查询语句

对应图标的三条查询语句为

 

sum(irate(kafka_topic_partition_current_offset{topic !~ "__consumer_offsets|__transaction_state|test",env="$env",app="$app"}[30s])) by (topic) >= 0

 

sum(kafka_consumergroup_lag{env="$env",app="$app"})  by (topic,consumergroup)

 

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

闽ICP备14008679号