文章目录
背景
因为项目启动中有卡顿问题,并有时还会奔溃,所以需要做一个实时显示JVM性能的仪表盘。
JMX_Exporter下载并配置
JMX_Exporter下载
JMX_Exporter配置
vim jmx_exporter_config.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
修改Prometheus配置文件
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: "prometheus"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["localhost:9090","192.168.1.101:9100","192.168.1.102:9100","192.168.1.103:9100","192.168.1.104:9100","192.168.1.105:9100","192.168.1.106:9100","192.168.1.158:9100"]
- job_name: "jvm"
static_configs:
- targets: ["192.168.1.158:8585","192.168.1.105:8585"]
重启Prometheus
项目启动脚本中修改
-javaagent:/自己的下面目录/jmx_prometheus_javaagent-0.14.0.jar=8585:/自己配置文件目录/jmx_exporter_config.yaml
导入Grafana模板
导入Grafana模板方式,导入8878模板
数据多样的问题(可跳过)
因为之前Prometheus中还有Linux服务器的状态信息,所以需要设置过滤信息
面板设置
Variables设置
添加Variables
添加job
label_values(job)
添加instance
label_values(up{job=~"$job"},instance)
完成Variables配置
保存仪表盘配置
编辑面板
添加属性
,job="$job",instance="$instance"
JVM数据展示
整个数据面板可以根据自己需求去拖拽