Prometheus (Grafana) Metrics Tomcat Configuration

Prometheus (Grafana) Metrics Tomcat Configuration

FullCount's Tomcat application servers are configured to export certain JMX MBean values to a metrics file. The metrics in this file are then collected by Prometheus and displayed in dashboards through Grafana.

To configure this monitoring, two files must be placed on the Tomcat server in /srv/tomcat/monitoring/

  • jmx_prometheus_javaagent-X.X.X.jar where X.X.X is the version of the .jar. This file is obtained from the JMX exporter project on GitHub. This .jar contains the mechanisms that export the metrics.
  • jmx_exporter_tomcat.yml. An example file can be found in the same repo. This is the configuration file that determines which MBeans are exported from Java to be collected in the metrics file.

The jmx_exporter_tomcat.yml file contains rules that specify regex patterns that match java MBean attributes. To find MBeans that we may want to capture in our metrics, we can browse MBeans on our local Tomcat servers by running the jconsole command in a command prompt.

Example: Capturing Servlet MBeans

We want to capture Servlet related metrics, so we find the ObjectNames we want nested in the Servlet folder in JConsole. If we check several of these beans, we can recognize that all the ObjectNames share a similar pattern. They all have a j2eeType of Servlet, a J2EEApplication of none, and J2EEServer of none. The WebModule and name values change from bean to bean, so we'll have to be a bit more lenient in that part of the regex pattern.

We also want to note the attributes we want to include as metrics (Ex: requestCount).

Since the MBeans are being read as .xml, we'll have to change the pattern a little bit. Here is what the final rule looks like in the .yml configuration:

  - pattern: 'Catalina<j2eeType=Servlet, WebModule=//([-a-zA-Z0-9+&@#/%?=~_|!:.,;]*[-a-zA-Z0-9+&@#/%=~_|]), name=([-a-zA-Z0-9+/$%~_-|!.]*), J2EEApplication=none, J2EEServer=none><>(requestCount|processingTime|errorCount):'

    name: tomcat_servlet_$3_total

    labels:

      module: "$2"

      servlet: "$1"

    help: Tomcat servlet $3 total

    type: COUNTER

Note the '<' and '>' characters in the pattern to accommodate the .xml format and that the WebModule and name attributes are regex tokens to account for the differences across beans. The last part of the pattern is another regex token will include the requestCount, processingTime, and errorCount attributes in our metrics.

Below the pattern, we specify the name of the metric that Prometheus will store it as. Here, we use the third regex token in the pattern to extract the attribute name. For example, the requestCount attribute will be named tomcat_servlet_requestCount_total in Prometheus.

We also extract the name and store it in the module label, and extract the WebModule and store it in the servlet label (This was set up backwards originally. Don't @ me)

 


    • Related Articles

    • Configure A Tomcat Instance to Use A Specific Version of Tomcat

      Configure A Tomcat Instance to Use A Specific Version of Tomcat Objectives 1. Configure a Tomcat instance to use a specific version of Tomcat. Prerequisites 1. Administrative privileges on the tomcat server that you would like to change. Instructions ...
    • Configure A Tomcat Instance to Use A Specific Version of the JDK

      Configure A Tomcat Instance to Use A Specific Version of the JDK Objectives Configure a Tomcat instance to use a specific version of the JDK. Prerequisites Administrative privileges on the tomcat server that you would like to change. Instructions 1. ...
    • iPad - Configuration/End User Setup/Troubleshoot Registration

      iPad - Configuration/End User Setup/Troubleshoot Registration FullCount POS iPad setup Approved Models Any model of iPad with iOS 15.1 or newer is compatible. In general, this only excludes iPads that were released prior to 2014. The latest version ...
    • Known Issues with DHCP and IP Configuration Requirements

      Known Issues with DHCP and IP Configuration Requirements DHCP has problems on OS image versions 3 through 5.X.X. It is required on these image versions to use static IP addresses or re-image the device with version 6.0.0 or higher if DHCP is required ...
    • Android Tablet - Configuration/End User Setup/Troubleshoot Registration

      Android Hardware Setup Approved Models Please see the hardware list of approved devices. https://kb.fullcount.net/documentation/fullcount-hardware-links Application Download Install the FullCount POS app on the device Search 'Fullcount POS' on the ...