配置JMX Exporter
下载jmx_exporter
1 2 3
| $ mkdir -p /opt/monitor/jmx_exporter $ chmod 777 -R /opt/monitor/jmx_exporter $ wget https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.3.1/jmx_prometheus_javaagent-0.3.1.jar
|
创建配置文件
1
| $ vi /opt/monitor/jmx_exporter/jmx_exporter.yml
|
jmx_exporter.yml文件内容如下:
1 2 3 4 5 6 7 8
| lowercaseOutputLabelNames: true lowercaseOutputName: true whitelistObjectNames: ["java.lang:type=OperatingSystem"] rules: - pattern: 'java.lang<type=OperatingSystem><>((?!process_cpu_time)w+):' name: os_$1 type: GAUGE attrNameSnakeCase: true
|
配置应用程序
普通运行
java -jar -javaagent:/opt/monitor/jmx_exporter/jmx_prometheus_javaagent-0.3.1.jar=8099:/opt/monitor/jmx_exporter/jmx_exporter.yml app.jar
docker运行
- 修改启动配置:添加
-javaagent:/opt/monitor/jmx_exporter/jmx_prometheus_javaagent-0.3.1.jar=8099:/opt/monitor/jmx_exporter/jmx_exporter.yml
- 挂载数据卷:
-v /opt/monitor/jmx_exporter:/opt/monitor/jmx_exporter
- 添加端口映射:
-p 8099:8099
- 创建容器
配置Prometheus拉取监控指标
- 在prometheus.yml中添加任务:
1 2 3 4 5 6 7
| scrape_configs: - job_name: 'java' scrape_interval: 30s static_configs: - targets: - 'ip:port' - 'ip:port'
|
- 重启prometheus
配置Grafana模板
- 配置Prometheus数据源
- 添加JVM dashboard模板