在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的运行状态,确保其稳定性和性能。