我正在尝试公开我的一些Spring应用程序指标(Spring)。这些指标主要是数据库连接指标。为此,我首先配置了一个hikari连接池,然后使用了jmx。要将指标导出到Prometheus,然后使用Grafana可视化它们,我尝试使用jmx_prometheus_exporter [https://github.com/prometheus/jmx_exporter][1]
我下载了jmx_exporter jar,然后在Tomcat8服务中添加了这一行(在init.d文件夹中)
export JAVA_OPTS =“ $ JAVA_OPTS -javaagent:/home/monitoring/jmx_prometheus_javaagent-0.3.0.jar=9095:/home/monitoring/config-jmx-tomcat.yaml“
这是tomcat的配置文件(config-jmx-tomcat.yaml)
lowercaseOutputLabelNames: true lowercaseOutputName: true rules:
- pattern: 'Catalina<type=GlobalRequestProcessor, name=\"(\w+-\w+)-(\d+)\"><>(\w+):' name: tomcat_$3_total labels:
port: "$2"
protocol: "$1" help: Tomcat global $3 type: COUNTER
- pattern: 'Catalina<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: 'Catalina<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: 'Catalina<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
在我的应用程序中,这就是定义连接池和MbeanServer的方式。
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
ObjectName poolName = new ObjectName("com.zaxxer.hikari:type=Pool (foo)");
HikariPoolMXBean poolProxy = JMX.newMXBeanProxy(mBeanServer, poolName, HikariPoolMXBean.class);
int idleConnections = poolProxy.getIdleConnections();
当我尝试加入localhost:9095 / metrics时,我什么也没找到,而Catalina日志,tomcat日志却什么也没显示。
我的问题是: