The Apache Tomcat integration collects traffic-related metrics, such as the
number of active sessions or network throughput. The integration also collects
access and Catalina logs. Access logs are parsed into a JSON payload
focused on request details, whereas Catalina logs are parsed for general
details. The tomcat
receiver collects telemetry from the Tomcat server's Java
Virtual Machine (JVM) via JMX.
For more information about Apache Tomcat, see tomcat.apache.org.
Prerequisites
To collect and ingest Tomcat logs and metrics, you must install Ops Agent version 2.9.0 or higher.
This receiver supports Apache Tomcat versions 9.0.x and 10.x.
Configure your Tomcat instance
To expose a JMX endpoint, you must set the com.sun.management.jmxremote.port
system property when starting the JVM. We also recommend setting the
com.sun.management.jmxremote.rmi.port
system property to the same port. To
expose a JMX endpoint remotely, you must also set the java.rmi.server.hostname
system property.
By default, these properties are set in a Tomcat deployment's
tomcat-env.sh
file.
To set system properties by using command-line arguments, prepend the property
name with -D
when starting the JVM. For example, to set
com.sun.management.jmxremote.port
to port 8050
, specify the following when
starting the JVM:
-Dcom.sun.management.jmxremote.port=8050
Configure the Ops Agent for Tomcat
Following the guide for Configuring the Ops Agent, add the required elements to collect logs and metrics from your Tomcat instances, and restart the agent.
Example configuration
The following command creates the configuration file to collect and ingest logs and metrics for Apache Tomcat and restarts the Ops Agent on Linux.
sudo tee /etc/google-cloud-ops-agent/config.yaml > /dev/null << EOF
logging:
receivers:
tomcat_system:
type: tomcat_system
tomcat_access:
type: tomcat_access
service:
pipelines:
tomcat:
receivers:
- tomcat_system
- tomcat_access
metrics:
receivers:
tomcat:
type: tomcat
service:
pipelines:
tomcat_pipeline:
receivers:
- tomcat
EOF
sudo service google-cloud-ops-agent restart
Configure logs collection
To ingest logs from Tomcat, you must create receivers for the logs that Tomcat produces and then create a pipeline for the new receivers.
To configure a receiver for your tomcat_system
logs, specify the following
fields:
Field | Default | Description |
---|---|---|
type |
The value must be tomcat_system . |
|
include_paths |
[/opt/tomcat/logs/catalina.out ] |
The log files to read. A wild card, (*), can be used in the paths; for example, /var/log/apache*/*.log . |
exclude_paths |
The log files to exclude, if include_paths contains a glob or directory. |
To configure a receiver for your tomcat_access
logs, specify the following
fields:
Field | Default | Description |
---|---|---|
type |
The value must be tomcat_access . |
|
include_paths |
[/opt/tomcat/logs/localhost_access_log.*.txt] |
The log files to read. |
exclude_paths |
[] |
The log files to exclude, if include_paths contains a glob or directory. |
What is logged
The logName
of the tomcat_system
and tomcat_access
logs are derived from
the receiver IDs specified in the configuration. Detailed fields inside the
LogEntry
are as follows.
tomcat_system
These logs contain the following fields in the
LogEntry
:
Field | Type | Description |
---|---|---|
timestamp |
string (Timestamp ) |
Time the request was received |
jsonPayload.module |
string | Module of tomcat where the log originated |
jsonPayload.source |
string | Source from where the log originated |
jsonPayload.message |
string | Log message, including detailed stack trace when provided |
severity |
string (LogSeverity ) |
Log entry level (translated) |
tomcat_access
These logs contain the following fields in the
LogEntry
:
Field | Type | Description |
---|---|---|
httpRequest.protocol |
string | Protocol used for the request |
httpRequest.referer |
string | Contents of the Referer header |
httpRequest.requestMethod |
string | HTTP method |
httpRequest.requestUrl |
string | Request URL (typically just the path part of the URL) |
httpRequest.responseSize |
string (int64 ) |
Response size |
httpRequest.status |
number | HTTP status code |
httpRequest.userAgent |
string | Contents of the User-Agent header |
jsonPayload.host |
string | Contents of the Host header |
jsonPayload.user |
string | Authenticated username for the request |
timestamp |
string (Timestamp ) |
Time the request was received |
Configure metrics collection
To collect metrics from Tomcat, you must create a receiver for Tomcat metrics and then create a pipeline for the new receiver. To configure a receiver for your Tomcat metrics, specify the following fields:
Field | Default | Description |
---|---|---|
type |
The value must be tomcat . |
|
endpoint |
localhost:8050 |
The JMX Service URL or host and port used to construct the service URL. This value must be in the form of service:jmx:<protocol>:<sap> or host:port . Values in host:port form are used to create a service URL of service:jmx:rmi:///jndi/rmi://<host>:<port>/jmxrmi . |
collect_jvm_metrics |
true |
Configures the receiver to also collect the supported JVM metrics. |
username |
The configured username if JMX is configured to require authentication. | |
password |
The configured password if JMX is configured to require authentication. | |
collection_interval |
60s |
A time.Duration value, such as 30s or 5m . |
What is monitored
The following table provides the list of metrics that the Ops Agent collects from the Tomcat instance.
Metric type | |
---|---|
Kind, Type Monitored resources |
Labels |
workload.googleapis.com/tomcat.errors
|
|
CUMULATIVE , INT64 gce_instance |
proto_handler
|
workload.googleapis.com/tomcat.max_time
|
|
GAUGE , INT64 gce_instance |
proto_handler
|
workload.googleapis.com/tomcat.processing_time
|
|
CUMULATIVE , INT64 gce_instance |
proto_handler
|
workload.googleapis.com/tomcat.request_count
|
|
CUMULATIVE , INT64 gce_instance |
proto_handler
|
workload.googleapis.com/tomcat.sessions
|
|
GAUGE , DOUBLE gce_instance |
|
workload.googleapis.com/tomcat.threads
|
|
GAUGE , INT64 gce_instance |
proto_handler
|
workload.googleapis.com/tomcat.traffic
|
|
CUMULATIVE , INT64 gce_instance |
proto_handler
direction
|
Sample dashboard
You can view the metrics from this integration using a sample Cloud Monitoring dashboard. Complete the Installing sample dashboards procedures to import the Tomcat GCE Overview dashboard from the Sample library and view charts that display your Apache Tomcat metrics.Verify the configuration
You can use the Logs Explorer and Metrics Explorer to verify that you correctly configured the Tomcat receiver. It might take one or two minutes for the Ops Agent to begin collecting logs and metrics.
To verify the logs are ingested, go to the Logs Explorer and run the following query to view the Tomcat logs:
resource.type="gce_instance"
logName=("projects/PROJECT_ID/logs/tomcast_system" OR "projects/PROJECT_ID/logs/tomcat_access")
To verify the metrics are ingested, go to
Metrics Explorer
and run the following query in the MQL tab.
fetch gce_instance
| metric 'workload.googleapis.com/tomcat.sessions'
| align rate(1m)
| every 1m