Prometheus+Grafana监控JVM

配置JMX Exporter

下载jmx_exporter

$ 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

创建配置文件

$ vi /opt/monitor/jmx_exporter/jmx_exporter.yml

jmx_exporter.yml文件内容如下:

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运行

  1. 修改启动配置:添加-javaagent:/opt/monitor/jmx_exporter/jmx_prometheus_javaagent-0.3.1.jar=8099:/opt/monitor/jmx_exporter/jmx_exporter.yml
  2. 挂载数据卷:-v /opt/monitor/jmx_exporter:/opt/monitor/jmx_exporter
  3. 添加端口映射:-p 8099:8099
  4. 创建容器

配置Prometheus拉取监控指标

  1. 在prometheus.yml中添加任务:
scrape_configs:
  - job_name: 'java'
    scrape_interval: 30s
    static_configs:
    - targets:
      - 'ip:port'
      - 'ip:port'
  1. 重启prometheus

配置Grafana模板

  1. 配置Prometheus数据源
  2. 添加JVM dashboard模板
posted @ 2021-02-25 20:47  天上的白云贼白了  阅读(395)  评论(0编辑  收藏  举报