1.jmx github地址
GitHub - prometheus/jmx_exporter: A process for exposing JMX Beans via HTTP for Prometheus consumption
2.jmx config
- 可以通过java.lang 采集机器cpu 内存等基础信息
https://github.com/prometheus/jmx_exporter/tree/master/example_configs
cat <<"EOF" > common.yaml
lowercaseOutputLabelNames: true
lowercaseOutputName: true
whitelistObjectNames: ["java.lang:type=OperatingSystem"]
blacklistObjectNames: []
rules:
- pattern: 'java.lang<type=OperatingSystem><>(committed_virtual_memory|free_physical_memory|free_swap_space|total_physical_memory|total_swap_space)size:'
name: os$1_bytes
type: GAUGE
attrNameSnakeCase: true- pattern: 'java.lang<type=OperatingSystem><>((?!process_cpu_time)\w+):'
name: os_$1
type: GAUGE
attrNameSnakeCase: true
EOF
3.自行下载安装好kafka和zk,这里不赘述
4.修改zookeeper 启动脚本
- 修改zookeeper 添加jmx_exporter.jar启动
- 在bin/zookeeper-server-start.sh 脚本EXTRA_ARGS 下面添加 EXTRA_ARGS
EXTRA_ARGS=${EXTRA_ARGS-'-name zookeeper -loggc'}
export EXTRA_ARGS="$EXTRA_ARGS -javaagent:/opt/app/jmx_exporter/jmx_prometheus_javaagent-0.16.0.jar=9142:/opt/app/jmx_exporter/common.yaml"
5.启动zk
- 使用安装包中的脚本启动单节点 Zookeeper 实例:
bin/kafka-run-class.sh +289 CONSOLE_OUTPUT_FILE可能报找不到,赋个别的值就可以了
bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
6.检查zk
- zookeeper启动应该listen 2181和9142端口
- ss -ntlp |grep java
7.修改kafka启动脚本, 添加jmx_exporter.jar启动
- 在bin/kafka-server-start.sh 脚本最上面添加下面这行
export KAFKA_OPTS="-javaagent:/opt/app/jmx_exporter/jmx_prometheus_javaagent-0.16.1.jar=9309:/opt/app/jmx_exporter/kafka-agent.yaml"
8.启动kafka
- 使用 kafka-server-start.sh 启动 kafka 服务:
- bin/kafka-server-start.sh -daemon config/server.properties
版权归原作者 Q·sun Ou 所有, 如有侵权,请联系我们删除。