kafka topic監控采集


使用開源的項目

直接通過編譯好的二進制文件部署

kafka_exporter二進制文件下載地址 下載 kafka_exporter-1.2.0.linux-amd64.tar.gz

1、啟動kafka_exporter

brokers=$1
export_port=$2 #從8308開始
for broker in `echo "${brokers}"|sed 's/,/\n/g'`;do
  opt="${opt} --kafka.server=${broker}"
done
nohup ./kafka_exporter ${opt} --sasl.username=1111 --sasl.password=1111 --sasl.enabled --web.listen-address=":${export_port}" &>>kafka_exporter.log&

2、部署prometheus,結合consul動態注冊服務

配置consul

1. 官網下載consul二進制文件
2. 啟動consul
nohup ./bin/consul agent -server -bootstrap-expect 1 -data-dir=./data -node=server1 -log-file=./logs/consul.log -bind=localhost -client=localhost -ui >consul_start.log &
3. 注冊服務
curl -X PUT -d '{"id": "kafka_export_1","name": "kafka_export_1","address": "localhost","port": 8308,"checks": [{"http": "http://localhost:8308/metrics","interval": "30s"}]}' http://localhost:8500/v1/agent/service/register
4. 刪除服務
curl -X PUT http://localhost:8500/v1/agent/service/deregister/kafka_export_1

下載prometheus-2.15.1.linux-amd64

配置

 

 

 

 最好是通過consul進行動態注冊服務,consul配置方式

promtheus 配置

 啟動prometheus

nohup ./prometheus --config.file=prometheus.yml --web.listen-address="0.0.0.0:8200" &>prometheus.log &

當consul注冊成功后可以在consul web http://localhost:8500/ui/dc1/services 看到注冊的服務

在prometheus web 端http://localhost:8200/targets 可以看到consul中的target

 

 

3、部署grafana

下載grafana-6.5.2-1.x86_64.rpm

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

由於服務器端做了限速,所以龜速下載

yum install grafana-6.5.2-1.x86_64.rpm
# 安裝完之后對於centos7,會自動配置system服務,服務配置文件
/usr/lib/systemd/system/grafana-server.service
# 配置文件
/usr/share/grafana/conf/defaults.ini
# 啟動服務
systemctl start grafana-server

 

4、配置grafana

添加datasource

 

 導入dashboard 模版,id為7589

 

添加自定義儀表盤

 

遇到的問題

由於有些集群的topic非常多導致grafana報表展示出錯

Request-URI Too Long

 

這是因為查詢語句中會拼接所有的topic,導致查詢參數太長請求發送失敗 

解決辦法

將查詢語句:

 

改為:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM