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

  1. # jmx agent
  2. git clone https://github.com/prometheus/jmx_exporter
  3. cd jmx_exporter
  4. mvn package
  5. ## 或者直接下载 jar包
  6. wget https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.11.0/jmx_prometheus_javaagent-0.11.0.jar
  7. # 获得jmx_export tomcat 的配置文件
  8. # https://github.com/prometheus/jmx_exporter/tree/master/example_configs
  9. cat > tomcat.yml <<EOF
  10. ---
  11. lowercaseOutputLabelNames: true
  12. lowercaseOutputName: true
  13. whitelistObjectNames: ["java.lang:type=OperatingSystem"]
  14. blacklistObjectNames: []
  15. rules:
  16. - pattern: 'java.lang<type=OperatingSystem><>(committed_virtual_memory|free_physical_memory|free_swap_space|total_physical_memory|total_swap_space)_size:'
  17. name: os_\$1_bytes
  18. type: GAUGE
  19. attrNameSnakeCase: true
  20. - pattern: 'java.lang<type=OperatingSystem><>((?!process_cpu_time)\w+):'
  21. name: os_\$1
  22. type: GAUGE
  23. attrNameSnakeCase: true
  24. EOF
  25. # 启动项目
  26. java -javaagent:./jmx_exporter/jmx_prometheus_javaagent/target/jmx_prometheus_javaagent-0.11.1-SNAPSHOT.jar=7788:tomcat.yml \
  27. -jar jersey-jar.war
  28. # 若在tomcat 中,要配置 setenv.sh
  29. cat > /usr/local/tomcat/bin/setenv.sh << EOF
  30. JAVA_OPTS="-javaagent:/usr/local/src/jvm/jmx_prometheus_javaagent-0.11.0.jar=7788:/usr/local/src/jvm/tomcat.yml"
  31. EOF
  32. chmod +x /usr/local/tomcat/bin/setenv.sh

prometheus 中加入配置

  1. scrape_configs:
  2. - job_name: 'java'
  3. static_configs:
  4. - targets: ['<host>:<port>']

grafana 模板

grafana 模板: https://grafana.com/dashboards/8563