Prometheus+Grafana+jmx_exporter 监控 Java 虚拟机

Prometheus Grafana DevOps About 1,513 words

agent 下载地址

https://github.com/prometheus/jmx_exporter/releases

配置文件样例

https://github.com/prometheus/jmx_exporter/tree/master/example_configs

配置文件

此配置文件Grafana Dashboard 8563中提供。

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

启动 jar

-javaagent配置代理,并指定端口和配置文件。

nohup java -javaagent:./jmx_prometheus_javaagent-0.16.1.jar=18080:sample_config.yml -jar demo.jar > demo.out 2>&1 &

修改 Prometheus 配置

scrape_configs下新增job_namejava(名称随意)

  - job_name: 'java'
    static_configs:
      - targets: ['192.168.0.100:18080']

完整的scrape_configs如下

scrape_configs:
  - job_name: "prometheus"
    static_configs:
      - targets: ["localhost:9090"]
  - job_name: 'java'
    static_configs:
      - targets: ['192.168.0.100:18080']

重启 Prometheus

重启后可查看jmx_exporter是否上线。

http://localhost:9090/targets

Grafana Dashboard

JVM dashboard: https://grafana.com/grafana/dashboards/8563

注意

Grafana Dashboard 8563中默认的job_namejava,如果在prometheus.yml配置的jmx_exporter不为java,可以更改Grafana导入时的job名称。

开源地址

https://github.com/prometheus/jmx_exporter/

Views: 2,340 · Posted: 2022-02-23

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh