搭建 Jmx_exporter + Prometheus + Grafana 监控kafka

一、 启动jmx_exporter

1. 下载并打包(mvn package)jmx_exporter

https://github.com/prometheus/jmx_exporter

测试jar包(kafka的jmx端口为9898):

java -cp collector/target/collector-0.15.1-SNAPSHOT.jar  io.prometheus.jmx.JmxScraper  service:jmx:rmi:///jndi/rmi://localhost:9898/jmxrmi

2. 修改example_configs\kafka-2_0_0.yml

在首行添加kafka的jmx地址:

hostPort: localhost:9898

3. 启动jmx_exporter为httpserver

Windows下启动:

java -cp .\jmx_prometheus_httpserver\target\jmx_prometheus_httpserver-0.15.1-SNAPSHOT-jar-with-dependencies.jar io.prometheus.jmx.WebServer 9997 .\example_configs\kafka-2_0_0.yml

4. 测试:

访问http://localhost:9997, 能正确返回数据

二、 启动Prometheus

1. 下载并解压缩Prometheus

https://prometheus.io/download/

2. 修改prometheus.yml

在scrape_configs节点下添加:

  - job_name: 'kafka_jmx_exporter'
    static_configs:
    - targets: ['localhost:9997']

3. 启动Prometheus

Windows: .\prometheus.exe
Linux: ./prometheus --config.file=prometheus.yml

三、 启动Grafana

1. 下载并解压Grafana

https://grafana.com/grafana/download

2. 启动Grafana

Windows: .\bin\grafana-server.exe
Linux: .\bin\grafana-server web

你可能感兴趣的:(java,Prometheus,Grafana,jmx_exporter,kafka,kafka监控)