监控tomcat 的工具


jmx_export 项目地址: https://github.com/prometheus/jmx_exporter

在项目中提供了配置文件: https://github.com/prometheus/jmx_exporter/tree/master/example_configs


# jmx agent
git clone https://github.com/prometheus/jmx_exporter
cd jmx_exporter
mvn 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_configs
cat > tomcat.yml <<EOF
---   
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
EOF

# 启动项目
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.sh
cat > /usr/local/tomcat/bin/setenv.sh << EOF
JAVA_OPTS="-javaagent:/usr/local/src/jvm/jmx_prometheus_javaagent-0.11.0.jar=7788:/usr/local/src/jvm/tomcat.yml"
EOF
chmod +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