How to Configure Tomcat with jmx exporter and get metrics on prometheus

98 views
Skip to first unread message

Mohammed Ayan

unread,
Jul 29, 2020, 2:13:02 AM7/29/20
to Prometheus Users
Hello,

I visited a link on git hub https://github.com/prometheus/jmx_exporter and seen the article in this part 
"
Running

To run as a javaagent download the jar and run:

java -javaagent:./jmx_prometheus_javaagent-0.13.0.jar=8080:config.yaml -jar yourJar.jar

Metrics will now be accessible at http://localhost:8080/metrics

"

but in my tomcat I dont have any jar file to run , In webapps I have war file projects , How I can configure tomcat for jmx exporter to get metrices on prometheus.

So far i have set up , tomcat with jmx and getting output in terminal.

master-node:~/apache/tomcat-instance3/bin$  ps -ef | grep tomcat

daffola+   21065    4366 17 11:31 pts/0    00:00:05 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java -Djava.util.logging.config.file=/home/daffolap-348/apache/tomcat-instance3/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=127.0.0.1 -Dcom.sun.management.jmxremote.rmi.port=10052 -Djava.net.preferIPv4Stack=true -Dignore.endorsed.dirs= -classpath /home/daffolap-348/apache/tomcat-instance3/bin/bootstrap.jar:/home/daffolap-348/apache/tomcat-instance3/bin/tomcat-juli.jar -Dcatalina.base=/home/daffolap-348/apache/tomcat-instance3 -Dcatalina.home=/home/daffolap-348/apache/tomcat-instance3 -Djava.io.tmpdir=/home/daffolap-348/apache/tomcat-instance3/temp org.apache.catalina.startup.Bootstrap start
daffola+   21247   20877  0 11:32 pts/0    00:00:00 grep --color=auto tomcat


 File: setenv.sh
CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=127.0.0.1 -Dcom.sun.management.jmxremote.rmi.port=10052 -Djava.net.preferIPv4Stack=true"







jro...@gmail.com

unread,
Jul 29, 2020, 5:22:57 AM7/29/20
to Prometheus Users
Hello Mohammed, from the ps -ef | grep tomcat output it doesn't look like the tomcat app is bound to the jmx exporter.
  1. Download the jmx_prometheus_javaagent-0.13.0.jar file to the local host and save it for instance in /opt/jmx_exporter. https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.13.0/jmx_prometheus_javaagent-0.13.0.jar
  2. Download or create your own config file for instance in /opt/jmx_exporter (config example: https://raw.githubusercontent.com/prometheus/jmx_exporter/master/example_configs/tomcat.yml)
  3. Update the setenv.sh file as shown below and save it.
  4. Restart Tomcat app for the exporter to bind to the app.
  5. Issue ps -ef | grep jmx_exporter to validate.
  6. You also issue netstat -tlpn | grep 8080
Update setenv.sh file to include the jmx_exporter as shown below. Make sure port 8080 is not already is use. I would recommend using port 9404 instead:

CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=127.0.0.1 -Dcom.sun.management.jmxremote.rmi.port=10052 -Djava.net.preferIPv4Stack=true
-javaagent:/opt/jmx_exporter/jmx_prometheus_javaagent-0.13.0.jar=8080:/opt/jmx_exporter/tomcat.yml"

Good luck!
Reply all
Reply to author
Forward
0 new messages