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)