DEV Community

Hisyam Johan
Hisyam Johan

Posted on • Updated on

Monitor Tomcat 9 with Prometheus


We will configure tomcat server for integration with Prometheus.


  • Tomcat 9
  • Docker
  • Centos 7

Setting up Tomcat to expose metrics
Firstly, we need to download jmx_prometheus_javaagent as jar and place it in /tmp. In this steps, we will be using version 0.16.1.

Second, we need to create file in $CATALINA_BASE/bin named and add this line into the file:-

Enter fullscreen mode Exit fullscreen mode

Third, we need to create file name config.yml in /tmp and add this line to the file:-

startDelaySeconds: 0
ssl: false
lowercaseOutputName: false
lowercaseOutputLabelNames: false
Enter fullscreen mode Exit fullscreen mode

Then, we need to restart Tomcat server and the metrics should be available at http://HOST_IP:8088/metrics

you can verify it by running ps -ef | grep tomcat

If not available, this could be you are not open port 8088. To do that, you may follow this step to open it.

firewall-cmd --zone=public --add-port=8088/tcp --permanent
firewall-cmd --reload
iptables-save | grep 8088
Enter fullscreen mode Exit fullscreen mode

Configure Prometheus

  1. Create file promethues.yml in /home/$USER. And add this line
  scrape_interval:     15s # By default, scrape targets every 15 seconds.

  # Attach these labels to any time series or alerts when communicating with
  # external systems (federation, remote storage, Alertmanager).
    monitor: 'codelab-monitor'

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # Override the global default and scrape targets from this job every 5 seconds.
    scrape_interval: 5s

      - targets: ['localhost:9090']
  - job_name: 'tomcat'
      - targets: ['HOST_IP:8088']

Enter fullscreen mode Exit fullscreen mode
  1. Run Prometheus as Docker container
 docker run -d --name=prometheus -p 9090:9090 -v /home/$USER/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus --config.                                                                                                             file=/etc/prometheus/prometheus.yml
Enter fullscreen mode Exit fullscreen mode
  1. Go to http://PROMETHEUS_IP:9090 and go to tab Status->Target. You will see that Tomcat server status.


If you're using Tomcat server as container you may execute this

docker run -d --name=myapp-p 8080:8080 -p 8088:8088 -v ~/<FILE_NAME>.war:/usr/local/tomcat/webapps/<FILE_NAME>.war -v ~/tomcat-metrics-config/ -v ~/tomcat-metrics-config:/tmp -v ~/logs/<FILE_NAME>.log:/usr/local/tomcat/bin/<FILE_NAME>.log tomcat:9-jdk8-corretto
# volume persistence for WAR & LOG file are optional
# make sure you placed the files in the correct location 
Enter fullscreen mode Exit fullscreen mode

Top comments (0)