在Linux上監控Kafka運行狀態有多種方法,以下是一些常用的工具和步驟:
Kafka-UI是一個快速且輕量的開源Web UI工具,專為管理和監控Apache Kafka集群而設計。它提供了一個直觀的界面,使得用戶能夠輕松地執行Kafka日常運維工作,如主題管理、消費者組查看和生產者測試等。并且支持跟蹤Kafka集群的關鍵指標,包括Broker、Topics、Partitions、生產和消費情況。
安裝步驟:
docker run -it -p 8080:8080 -e DYNAMIC_CONFIG_ENABLED=true provectuslabs/kafka-ui
version: '3'
services:
kafka-ui:
container_name: kafka-ui
image: provectuslabs/kafka-ui:latest
ports:
- "8080:8080"
environment:
- DYNAMIC_CONFIG_ENABLED=true
volumes:
- ~/kui/config.yml:/etc/kafkaui/dynamic_config.yaml
helm repo add kafka-ui https://provectus.github.io/kafka-ui-charts
helm install kafka-ui kafka-ui/kafka-ui
部署完成后,通過http://hostip:8080
訪問界面。
cd /usr/local/appserver
wget https://github.com/danielqsj/kafka_exporter/releases/download/v1.2.0/kafka_exporter-1.2.0.linux-amd64.tar.gz
tar -xzf kafka_exporter-1.2.0.linux-amd64.tar.gz
mv kafka_exporter-1.2.0.linux-amd64 kafka_exporter
編輯/etc/supervisord.d/kafka_exporter.ini
文件:
[program:kafka_exporter]
command=/usr/local/appserver/kafka_exporter/kafka_exporter --kafka.server=kafka-1:19091 --kafka.server=kafka-2:19092 --kafka.server=kafka-3:19093 --kafka.server=kafka-4:19094 --kafka.server=kafka-5:19095
autostart=true
autorestart=true
startsecs=5
priority=1
startretries=3
stopwaitsecs=1
stdout_logfile=/data/logs/kafka_exporter.log
編輯prometheus.yml
文件,添加Kafka監控配置:
job_name: 'kafka'
scrape_interval: 5s
file_sd_configs:
- refresh_interval: 1m
files:
- "configs/SHN_Kafka_Service.yml"
curl -X POST http://127.0.0.1:9090/-/reload
輸入Prometheus提供的代碼7589以上。
通過上述方法,您可以在Linux上有效地監控Kafka的運行狀態,確保其穩定性和性能。