赞
踩
prometheus监控kafka常见的有两种开源方案,一种是传统的部署exporter的方式,一种是通过jmx配置监控,本文将采用第二种方式进行配置。
现有kafka三节点的集群,环境大概如下:
主机 | 组件 |
---|---|
10.3.0.41–node1 | zookeeper,kafka |
10.3.0.42–node2 | zookeeper,kafka |
10.3.20.4–node3 | zookeeper,kafka |
接着分别在如上三台主机上进行如下配置:
wget https://raw.githubusercontent.com/prometheus/jmx_exporter/master/example_configs/kafka-2_0_0.yml
wget https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.12.0/jmx_prometheus_javaagent-0.12.0.jar
分别创建统一的配置放置目录:
mkdir -p /usr/local/kafka/jmx/
mv kafka-2_0_0.yml /usr/local/kafka/jmx/kafka-2_0_0.yml
mv jmx_prometheus_javaagent-0.12.0.jar /usr/local/kafka/jmx/jmx_prometheus_javaagent-0.12.0.jar
然后在启动的配置文件中添加如下两行:
$ cat bin/kafka-server-start.sh
if [ $# -lt 1 ];
then
echo "USAGE: $0 [-daemon] server.properties [--override property=value]*"
exit 1
fi
base_dir=$(dirname $0)
if [ "x$KAFKA_LOG4J_OPTS" = "x" ]; then
export KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:$base_dir/../config/log4j.properties"
fi
if [ "x$KAFKA_HEAP_OPTS" = "x" ]; then
export KAFKA_HEAP_OPTS="-Xmx1G -Xms1G"
fi
EXTRA_ARGS=${EXTRA_ARGS-'-name kafkaServer -loggc'}
#如下两行内容
export JMX_PORT="9999"
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"
COMMAND=$1
case $COMMAND in
-daemon)
EXTRA_ARGS="-daemon "$EXTRA_ARGS
shift
;;
*)
;;
esac
exec $base_dir/kafka-run-class.sh $EXTRA_ARGS kafka.Kafka "$@"
然后重启kafka。
$ vim /usr/local/prometheus/prometheus.yml
- job_name: 'kafka-cluster'
scrape_interval: 5s
static_configs:
- targets: ['10.3.0.41:9991']
- targets: ['10.3.0.42:9991']
- targets: ['10.3.20.4:9991']
重启服务。
$ systemctl restart prometheus
或者通过命令热加载:
curl -XPOST localhost:9090/-/reload
展示模板通过ID进行导入,可用ID有:7589
,10466
,11963
等等
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。