Apache Tomcat integration for Grafana Cloud
Apache Tomcat is an open source web server and servlet container that can run Java-based web applications. This integration for Grafana Cloud allows users to collect metrics and logs for monitoring an Apache Tomcat instance.
Metrics include virtual memory and cpu usage, traffic sent and received, total requests and processing time, threads, sessions and session processing time, and servlet requests and servlet processing time.
This integration includes 4 useful alerts and 2 pre-built dashboards to help monitor and visualize Apache Tomcat metrics and logs.
Before you begin
In order for the integration to properly work, you must set up the JMX Exporter for Prometheus to export metrics from Tomcat.
To enable JMX collection, make sure your Tomcat instance is configured with the following CATALINA_OPTS:
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=9010
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
Set up JMX Exporter
The JMX Exporter can be run with this Apache Tomcat JMX Exporter configuration file.
For more information on how to configure the JVM, please refer to the JMX Exporter documentation for further configuration.
Apache Tomcat exposes 9010
for JMX by default, but feel free to change the port to match your environment. The JMX URL for the exporter should be properly configured to match e.g. jmxUrl: service:jmx:rmi:///jndi/rmi://localhost:9010/jmxrmi
Once deployed, Grafana Alloy should be able to reach the JMX Exporter’s exposed endpoint in order to scrape metrics.
Install Apache Tomcat integration for Grafana Cloud
- In your Grafana Cloud stack, click Connections in the left-hand menu.
- Find Apache Tomcat and click its tile to open the integration.
- Review the prerequisites in the Configuration Details tab and set up Grafana Agent to send Apache Tomcat metrics and logs to your Grafana Cloud instance.
- Click Install to add this integration’s pre-built dashboards and alerts to your Grafana Cloud instance, and you can start monitoring your Apache Tomcat setup.
Configuration snippets for Grafana Alloy
Simple mode
These snippets are configured to scrape a single Apache Tomcat node running locally with default ports.
Manually copy and append the following snippets into your Grafana Alloy configuration file.
Metrics snippets
discovery.relabel "metrics_integrations_tomcat" {
targets = [{
__address__ = "localhost:9010",
}]
rule {
target_label = "instance"
replacement = constants.hostname
}
}
prometheus.scrape "metrics_integrations_tomcat" {
targets = discovery.relabel.metrics_integrations_tomcat.output
forward_to = [prometheus.remote_write.metrics_service.receiver]
job_name = "integrations/tomcat"
}
Logs snippets
darwin
local.file_match "logs_integrations_tomcat_linux" {
path_targets = [{
__address__ = "localhost",
__path__ = "/{var,opt,usr/local}/{log,*tomcat*}/{*tomcat*,logs}/catalina.out",
instance = constants.hostname,
job = "integrations/tomcat",
}]
}
loki.source.file "logs_integrations_tomcat_linux" {
targets = local.file_match.logs_integrations_tomcat_linux.targets
forward_to = [loki.write.grafana_cloud_loki.receiver]
}
linux
local.file_match "logs_integrations_tomcat_linux" {
path_targets = [{
__address__ = "localhost",
__path__ = "/{var,opt,usr/local}/{log,*tomcat*}/{*tomcat*,logs}/catalina.out",
instance = constants.hostname,
job = "integrations/tomcat",
}]
}
loki.source.file "logs_integrations_tomcat_linux" {
targets = local.file_match.logs_integrations_tomcat_linux.targets
forward_to = [loki.write.grafana_cloud_loki.receiver]
}
windows
local.file_match "logs_integrations_tomcat_windows" {
path_targets = [{
__address__ = "localhost",
__path__ = "/Program Files/Apache Software Foundation/Tomcat *.*/logs/catalina.out",
instance = constants.hostname,
job = "integrations/tomcat",
}]
}
loki.source.file "logs_integrations_tomcat_windows" {
targets = local.file_match.logs_integrations_tomcat_windows.targets
forward_to = [loki.write.grafana_cloud_loki.receiver]
}
Advanced mode
To instruct Grafana Alloy to scrape your Apache Tomcat nodes, go though the subsequent instructions.
The snippets provide examples to guide you through the configuration process.
First, manually copy and append the following snippets into your Grafana Alloy configuration file.
Then follow the instructions below to modify the necessary variables.
Advanced metrics snippets
discovery.relabel "metrics_integrations_tomcat" {
targets = [{
__address__ = "localhost:9010",
}]
rule {
target_label = "instance"
replacement = constants.hostname
}
}
prometheus.scrape "metrics_integrations_tomcat" {
targets = discovery.relabel.metrics_integrations_tomcat.output
forward_to = [prometheus.remote_write.metrics_service.receiver]
job_name = "integrations/tomcat"
}
After enabling the JMX exporter in your Apache Tomcat node, instruct Grafana Alloy to scrape it.
One discovery.relabel must be added for each Apache Tomcat node.
Configure the following properties within each discovery.relabel
component:
__address__
: The address to the JMX exporter metrics endpoint.instance
:constants.hostname
sets theinstance
label to your Grafana Alloy server hostname. If that is not suitable, change it to a value uniquely identifies this Apache Tomcat instance. Make sure this label value is the same for all telemetry data collected for this instance.
Finally, reference each discovery.relabel
component within the targets
property of the prometheus.scrape component.
Advanced logs snippets
darwin
local.file_match "logs_integrations_tomcat_linux" {
path_targets = [{
__address__ = "localhost",
__path__ = "/{var,opt,usr/local}/{log,*tomcat*}/{*tomcat*,logs}/catalina.out",
instance = constants.hostname,
job = "integrations/tomcat",
}]
}
loki.source.file "logs_integrations_tomcat_linux" {
targets = local.file_match.logs_integrations_tomcat_linux.targets
forward_to = [loki.write.grafana_cloud_loki.receiver]
}
To collect logs from unix-like systems, you need a pair of loki.source.file, and local.file_match components of Grafana Alloy.
The provided snippet is pre-configured with the default log write location for unix-like environments.
If you wish to capture other log files, you must add new maps to the path_targets
list parameter of the local.file_match
component, and include it in the targets
list of loki.source.file
component. Make sure that the new entry has the same instance and job labels, so it is matched to the correct instance to be shown in the Logs dashboard.
linux
local.file_match "logs_integrations_tomcat_linux" {
path_targets = [{
__address__ = "localhost",
__path__ = "/{var,opt,usr/local}/{log,*tomcat*}/{*tomcat*,logs}/catalina.out",
instance = constants.hostname,
job = "integrations/tomcat",
}]
}
loki.source.file "logs_integrations_tomcat_linux" {
targets = local.file_match.logs_integrations_tomcat_linux.targets
forward_to = [loki.write.grafana_cloud_loki.receiver]
}
To collect logs from unix-like systems, you need a pair of loki.source.file, and local.file_match components of Grafana Alloy.
The provided snippet is pre-configured with the default log write location for unix-like environments.
If you wish to capture other log files, you must add new maps to the path_targets
list parameter of the local.file_match
component, and include it in the targets
list of loki.source.file
component. Make sure that the new entry has the same instance and job labels, so it is matched to the correct instance to be shown in the Logs dashboard.
windows
local.file_match "logs_integrations_tomcat_windows" {
path_targets = [{
__address__ = "localhost",
__path__ = "/Program Files/Apache Software Foundation/Tomcat *.*/logs/catalina.out",
instance = constants.hostname,
job = "integrations/tomcat",
}]
}
loki.source.file "logs_integrations_tomcat_windows" {
targets = local.file_match.logs_integrations_tomcat_windows.targets
forward_to = [loki.write.grafana_cloud_loki.receiver]
}
To collect logs from Windows systems, you need a pair of loki.source.file
, and local.file_match
components of Grafana Alloy.
The provided snippet is pre-configured with the default log write location for Windows environments.
If you wish to capture other log files, you must add new maps to the path_targets
list parameter of the local.file_match
component, and include it in the targets
list of loki.source.file
component. Make sure that the new entry has the same instance and job labels, so it is matched to the correct instance to be shown in the Logs dashboard.
Grafana Agent static configuration (deprecated)
The following section shows configuration for running Grafana Agent in static mode which is deprecated. You should use Grafana Alloy for all new deployments.
Before you begin
In order for the integration to properly work, you must set up the JMX Exporter for Prometheus to export metrics from Tomcat.
To enable JMX collection, make sure your Tomcat instance is configured with the following CATALINA_OPTS:
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=9010
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
Set up JMX Exporter
The JMX Exporter can be run with this Apache Tomcat JMX Exporter configuration file.
For more information on how to configure the JVM, please refer to the JMX Exporter documentation for further configuration.
Apache Tomcat exposes 9010
for JMX by default, but feel free to change the port to match your environment. The JMX URL for the exporter should be properly configured to match e.g. jmxUrl: service:jmx:rmi:///jndi/rmi://localhost:9010/jmxrmi
Once deployed, the Grafana Agent should be able to reach the JMX Exporter’s exposed endpoint in order to scrape metrics.
Install Apache Tomcat integration for Grafana Cloud
- In your Grafana Cloud stack, click Connections in the left-hand menu.
- Find Apache Tomcat and click its tile to open the integration.
- Review the prerequisites in the Configuration Details tab and set up Grafana Agent to send Apache Tomcat metrics and logs to your Grafana Cloud instance.
- Click Install to add this integration’s pre-built dashboards and alerts to your Grafana Cloud instance, and you can start monitoring your Apache Tomcat setup.
Post-install configuration for the Apache Tomcat integration
After enabling the metrics generation, instruct the Grafana Agent to scrape your Apache Tomcat nodes.
Make sure to change targets
in the snippet according to your environment.
If you want to show logs and metrics signals correlated in your dashboards as a single pane of glass, ensure the following:
job
andinstance
label values must match for the Apache Tomcat integration andlogs
scrape config in your agent configuration file.job
label must be set tointegrations/tomcat
(already configured in the snippets)instance
label must be set to a value that uniquely identifies your Apache Tomcat node. Please replace the defaulthostname
value according to your environment - it should be set manually. Note that if you uselocalhost
for multiple nodes, the dashboards will not be able to filter correctly by instance.
For the logs section, you may remove the job that does not correspond to your OS (e.g. remove the job with the /{var,opt}...
path on Windows systems).
Configuration snippets for Grafana Agent
Below metrics.configs.scrape_configs
, insert the following lines and change the URLs according to your environment:
- job_name: integrations/tomcat
metrics_path: /metrics
relabel_configs:
- replacement: '<your-instance-name>'
target_label: instance
static_configs:
- targets:
- localhost:12345
Below logs.configs.scrape_configs
, insert the following lines according to your environment.
- job_name: integrations/tomcat
static_configs:
- targets: [localhost]
labels:
instance: '<your-instance-name>'
__path__: /{var,opt}/{log,tomcat}/{tomcat*,logs}/catalina.out
- job_name: integrations/tomcat
static_configs:
- targets: [localhost]
labels:
instance: '<your-instance-name>'
__path__: "/Program Files/Apache Software Foundation/Tomcat *.*/logs/catalina.out"
Full example configuration for Grafana Agent
Refer to the following Grafana Agent configuration for a complete example that contains all the snippets used for the Apache Tomcat integration. This example also includes metrics that are sent to monitor your Grafana Agent instance.
integrations:
prometheus_remote_write:
- basic_auth:
password: <your_prom_pass>
username: <your_prom_user>
url: <your_prom_url>
agent:
enabled: true
relabel_configs:
- action: replace
source_labels:
- agent_hostname
target_label: instance
- action: replace
target_label: job
replacement: "integrations/agent-check"
metric_relabel_configs:
- action: keep
regex: (prometheus_target_sync_length_seconds_sum|prometheus_target_scrapes_.*|prometheus_target_interval.*|prometheus_sd_discovered_targets|agent_build.*|agent_wal_samples_appended_total|process_start_time_seconds)
source_labels:
- __name__
# Add here any snippet that belongs to the `integrations` section.
# For a correct indentation, paste snippets copied from Grafana Cloud at the beginning of the line.
logs:
configs:
- clients:
- basic_auth:
password: <your_loki_pass>
username: <your_loki_user>
url: <your_loki_url>
name: integrations
positions:
filename: /tmp/positions.yaml
scrape_configs:
# Add here any snippet that belongs to the `logs.configs.scrape_configs` section.
# For a correct indentation, paste snippets copied from Grafana Cloud at the beginning of the line.
- job_name: integrations/tomcat
static_configs:
- targets: [localhost]
labels:
instance: '<your-instance-name>'
__path__: /{var,opt}/{log,tomcat}/{tomcat*,logs}/catalina.out
- job_name: integrations/tomcat
static_configs:
- targets: [localhost]
labels:
instance: '<your-instance-name>'
__path__: "/Program Files/Apache Software Foundation/Tomcat *.*/logs/catalina.out"
metrics:
configs:
- name: integrations
remote_write:
- basic_auth:
password: <your_prom_pass>
username: <your_prom_user>
url: <your_prom_url>
scrape_configs:
# Add here any snippet that belongs to the `metrics.configs.scrape_configs` section.
# For a correct indentation, paste snippets copied from Grafana Cloud at the beginning of the line.
- job_name: integrations/tomcat
metrics_path: /metrics
relabel_configs:
- replacement: '<your-instance-name>'
target_label: instance
static_configs:
- targets:
- localhost:12345
global:
scrape_interval: 60s
wal_directory: /tmp/grafana-agent-wal
Dashboards
The Apache Tomcat integration installs the following dashboards in your Grafana Cloud instance to help monitor your system.
- Apache Tomcat hosts
- Apache Tomcat overview
Apache Tomcat overview dashboard 1
Apache Tomcat overview dashboard 2
Apache Tomcat hosts dashboard
Alerts
The Apache Tomcat integration includes the following useful alerts:
Alert | Description |
---|---|
ApacheTomcatAlertsHighCpuUsage | Critical: The instance has a CPU usage higher than the configured threshold. |
ApacheTomcatAlertsHighMemoryUsage | Critical: The instance has a higher memory usage than the configured threshold. |
ApacheTomcatAlertsHighRequestErrorPercent | Critical: There are a high number of request errors. |
ApacheTomcatAlertsModeratelyHighProcessingTime | Warning: The processing time has been moderately high. |
Metrics
The most important metrics provided by the Apache Tomcat integration, which are used on the pre-built dashboards and Prometheus alerts, are as follows:
- jvm_memory_usage_used_bytes
- jvm_physical_memory_bytes
- jvm_process_cpu_load
- tomcat_bytesreceived_total
- tomcat_bytessent_total
- tomcat_errorcount_total
- tomcat_processingtime_total
- tomcat_requestcount_total
- tomcat_servlet_errorcount_total
- tomcat_servlet_processingtime_total
- tomcat_servlet_requestcount_total
- tomcat_session_expiredsessions_total
- tomcat_session_processingtime_total
- tomcat_session_rejectedsessions_total
- tomcat_session_sessioncounter_total
- tomcat_threadpool_connectioncount
- tomcat_threadpool_currentthreadcount
- tomcat_threadpool_keepalivecount
- tomcat_threadpool_pollerthreadcount
- up
Changelog
# 1.1.0 - September 2024
* Added Asserts support
# 1.0.1 - March 2024
* Updated to latest Mixin to fix CPU and Memory Alert queries
# 1.0.0 - October 2023
* Added Grafana Agent Operator configuration snippet to support Tomcat in kubernetes cluster
* Added cluster selector to dashboard for kubernetes support
# 0.0.4 - September 2023
* New Filter Metrics option for configuring the Grafana Agent, which saves on metrics cost by dropping any metric not used by this integration. Beware that anything custom built using metrics that are not on the snippet will stop working.
* New hostname relabel option, which applies the instance name you write on the text box to the Grafana Agent configuration snippets, making it easier and less error prone to configure this mandatory label.
# 0.0.3 - August 2023
* Add regex filter for logs datasource
# 0.0.2 - July 2023
* Update mixin to latest version
- Adds an `instance` and `job` filter for the logs panel to only show this integration's logs
# 0.0.1 - April 2023
* Initial release
Cost
By connecting your Apache Tomcat instance to Grafana Cloud, you might incur charges. To view information on the number of active series that your Grafana Cloud account uses for metrics included in each Cloud tier, see Active series and dpm usage and Cloud tier pricing.