0. 参考
1. 工具准备
jar_config.yamljmx_prometheus_javaagent-0.13.0.jar
jar_config.yaml
---
lowercaseOutputLabelNames: true
lowercaseOutputName: true
rules:
- pattern: 'Tomcat<type=GlobalRequestProcessor, name=\"(\w+-\w+)-(\d+)\"><>(\w+):'
name: tomcat_$3_total
labels:
port: "$2"
protocol: "$1"
help: Tomcat global $3
type: COUNTER
- 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):'
name: tomcat_servlet_$3_total
labels:
module: "$1"
servlet: "$2"
help: Tomcat servlet $3 total
type: COUNTER
- pattern: 'Tomcat<type=ThreadPool, name="(\w+-\w+)-(\d+)"><>(currentThreadCount|currentThreadsBusy|keepAliveCount|pollerThreadCount|connectionCount):'
name: tomcat_threadpool_$3
labels:
port: "$2"
protocol: "$1"
help: Tomcat threadpool $3
type: GAUGE
- pattern: 'Tomcat<type=Manager, host=([-a-zA-Z0-9+&@#/%?=~_|!:.,;]*[-a-zA-Z0-9+&@#/%=~_|]), context=([-a-zA-Z0-9+/$%~_-|!.]*)><>(processingTime|sessionCounter|rejectedSessions|expiredSessions):'
name: tomcat_session_$3_total
labels:
context: "$2"
host: "$1"
help: Tomcat session $3 total
type: COUNTER
2. start
2.1 直接使用上面的工具(我修改好了的)
2.2 启动 jar
## 让 jmx_exporter 跟 jar 实例一起启动 注意端口(jmx_prometheus_javaagent-0.13.0.jar=30015)
## 多个jar都在用的情况要使用不同的端口
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
- job_name: 'eco'
scrape_interval: 10s
static_configs:
- targets: ['localhost:30015']
labels:
instance: eco
4. 配置图例(不要按照上面参考文件的修改图例配置)
图例: https://grafana.com/grafana/dashboards/8563 (其他的没有测试成功)