I am trying to expose some of my spring application metrics (Spring). The metrics are mainly database connection metrics. To do so, I started by configuring a hikari connection pool, then I used jmx. To export the metrics to prometheus then visiualize them with Grafana, I tried to used jmx_prometheus_exporter [https://github.com/prometheus/jmx_exporter][1]
I downlaoded the jmx_exporter jar and then I added this line in my Tomcat8 service (in the folder init.d)
export JAVA_OPTS=”$JAVA_OPTS
-javaagent:/home/monitoring/jmx_prometheus_javaagent-0.3.0.jar=9095:/home/monitoring/config-jmx-tomcat.yaml”This the config file file for 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
In my application This is how I define the connection pool and 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();
When I try to acceed to localhost:9095/metrics, I find nothing, and the catalina logs, tomcat logs, show nothing.
My questions are:
- Are the steps that I am following are correct or not?
- How can I debug or where should I see the errors?
- I keep finding tutorials showing conifgs with jmx remote . When to use this ?
thank you in advance for your response.
Answer
Attribution
Source : Link , Question Author : ch.E , Answer Author : Community