监控tomcat 的工具
- jmx_export
 - jmx_exporter tomcat 配置文件
 - 一个jar项目(jersey-jar.war) 或者 tomcat
 
jmx_export 项目地址: https://github.com/prometheus/jmx_exporter
在项目中提供了配置文件: https://github.com/prometheus/jmx_exporter/tree/master/example_configs
# jmx agentgit clone https://github.com/prometheus/jmx_exportercd jmx_exportermvn package## 或者直接下载 jar包wget https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.11.0/jmx_prometheus_javaagent-0.11.0.jar# 获得jmx_export tomcat 的配置文件# https://github.com/prometheus/jmx_exporter/tree/master/example_configscat > tomcat.yml <<EOF---lowercaseOutputLabelNames: truelowercaseOutputName: truewhitelistObjectNames: ["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_bytestype: GAUGEattrNameSnakeCase: true- pattern: 'java.lang<type=OperatingSystem><>((?!process_cpu_time)\w+):'name: os_\$1type: GAUGEattrNameSnakeCase: trueEOF# 启动项目java -javaagent:./jmx_exporter/jmx_prometheus_javaagent/target/jmx_prometheus_javaagent-0.11.1-SNAPSHOT.jar=7788:tomcat.yml \-jar jersey-jar.war# 若在tomcat 中,要配置 setenv.shcat > /usr/local/tomcat/bin/setenv.sh << EOFJAVA_OPTS="-javaagent:/usr/local/src/jvm/jmx_prometheus_javaagent-0.11.0.jar=7788:/usr/local/src/jvm/tomcat.yml"EOFchmod +x /usr/local/tomcat/bin/setenv.sh
prometheus 中加入配置
scrape_configs:- job_name: 'java'static_configs:- targets: ['<host>:<port>']
grafana 模板
grafana 模板: https://grafana.com/dashboards/8563
