1.jmx github地址

GitHub - prometheus/jmx_exporter: A process for exposing JMX Beans via HTTP for Prometheus consumption

wget https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.16.1/jmx_prometheus_javaagent-0.16.1.jar

2.jmx config 

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

 

Logo

Kafka开源项目指南提供详尽教程,助开发者掌握其架构、配置和使用,实现高效数据流管理和实时处理。它高性能、可扩展,适合日志收集和实时数据处理,通过持久化保障数据安全,是企业大数据生态系统的核心。

更多推荐