0. 参考

1. 工具准备

jar_config.yamljmx_prometheus_javaagent-0.13.0.jar

jar_config.yaml

  1. ---
  2. lowercaseOutputLabelNames: true
  3. lowercaseOutputName: true
  4. rules:
  5. - pattern: 'Tomcat<type=GlobalRequestProcessor, name=\"(\w+-\w+)-(\d+)\"><>(\w+):'
  6. name: tomcat_$3_total
  7. labels:
  8. port: "$2"
  9. protocol: "$1"
  10. help: Tomcat global $3
  11. type: COUNTER
  12. - pattern: 'Tomcat<j2eeType=Servlet, WebModule=//([-a-zA-Z0-9+&@#/%?=~_|!:.,;]*[-a-zA-Z0-9+&@#/%=~_|]), name=([-a-zA-Z0-9+/$%~_-|!.]*), J2EEApplication=none, J2EEServer=none><>(requestCount|maxTime|processingTime|errorCount):'
  13. name: tomcat_servlet_$3_total
  14. labels:
  15. module: "$1"
  16. servlet: "$2"
  17. help: Tomcat servlet $3 total
  18. type: COUNTER
  19. - pattern: 'Tomcat<type=ThreadPool, name="(\w+-\w+)-(\d+)"><>(currentThreadCount|currentThreadsBusy|keepAliveCount|pollerThreadCount|connectionCount):'
  20. name: tomcat_threadpool_$3
  21. labels:
  22. port: "$2"
  23. protocol: "$1"
  24. help: Tomcat threadpool $3
  25. type: GAUGE
  26. - pattern: 'Tomcat<type=Manager, host=([-a-zA-Z0-9+&@#/%?=~_|!:.,;]*[-a-zA-Z0-9+&@#/%=~_|]), context=([-a-zA-Z0-9+/$%~_-|!.]*)><>(processingTime|sessionCounter|rejectedSessions|expiredSessions):'
  27. name: tomcat_session_$3_total
  28. labels:
  29. context: "$2"
  30. host: "$1"
  31. help: Tomcat session $3 total
  32. type: COUNTER

2. start

2.1 直接使用上面的工具(我修改好了的)

2.2 启动 jar

  1. ## jmx_exporter jar 实例一起启动 注意端口(jmx_prometheus_javaagent-0.13.0.jar=30015
  2. ## 多个jar都在用的情况要使用不同的端口
  3. nohup java -javaagent:/doc/program/eco/jmx_prometheus_javaagent-0.13.0.jar=30015:/doc/program/eco/jar_config.yaml -Dfile.encoding=utf-8 -Dspring.profiles.active=prod -Xms256m -Xmx512m -jar /doc/program/eco/eco.war > /dev/null 2>&1 &

3. 配置 prometheus.yaml 后重启prometheus

  1. - job_name: 'eco'
  2. scrape_interval: 10s
  3. static_configs:
  4. - targets: ['localhost:30015']
  5. labels:
  6. instance: eco

4. 配置图例(不要按照上面参考文件的修改图例配置)

图例: https://grafana.com/grafana/dashboards/8563 (其他的没有测试成功)