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, 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 prequisites in the Configuration Details tab and set up Grafana Agent by following the steps provided to start sending 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 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
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 config example also includes metrics that are sent to monitor your Grafana Agent instance. Remember to replace URLs, credentials, and labels according to your stack and instructions in the previous section.
integrations:
agent:
enabled: true
relabel_configs:
- action: replace
source_labels:
- agent_hostname
target_label: instance
metric_relabel_configs:
- action: keep
regex: (prometheus_target_.*|prometheus_sd_discovered_targets|agent_build.*|agent_wal_samples_appended_total|process_start_time_seconds)
source_labels:
- __name__
prometheus_remote_write:
- basic_auth:
password: <your_prom_pass>
username: <your_prom_user>
url: <your_prom_url>
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:
- 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:
- job_name: integrations/tomcat
metrics_path: /metrics
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 dashboards (and Prometheus Alerts and rules) 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
Changelog
# 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.