Apache Tomcat
StackState Self-hosted v4.5.x

Overview

This check collects Tomcat metrics, for example:
  • Overall activity metrics: error count, request count, processing times
  • Thread pool metrics: thread count, number of threads busy
  • Servlet processing times
And more.

Setup

Installation

The Tomcat check is included in the Agent V2 StackPack, so you don't need to install anything else on your Tomcat servers.
This check is JMX-based, so you need to enable JMX Remote on your Tomcat servers. Follow the instructions in the Tomcat documentation to do that.

Configuration

  1. 1.
    Edit the tomcat.d/conf.yaml file, in the conf.d/ folder at the root of your Agent's configuration directory to start collecting your Tomcat metrics and logs. See the sample tomcat.d/conf.yaml for all available configuration options.
  2. 2.
    Restart the Agent

Metric Collection

  • Add this configuration block to your tomcat.yaml file to start gathering your Tomcat metrics:
1
instances:
2
- host: localhost
3
port: 7199
4
user: <TOMCAT_USERNAME>
5
password: <PASSWORD>
6
name: my_tomcat
7
​
8
init_config:
9
conf:
10
- include:
11
type: ThreadPool
12
attribute:
13
maxThreads:
14
alias: tomcat.threads.max
15
metric_type: gauge
16
currentThreadCount:
17
alias: tomcat.threads.count
18
metric_type: gauge
19
currentThreadsBusy:
20
alias: tomcat.threads.busy
21
metric_type: gauge
22
- include:
23
type: GlobalRequestProcessor
24
attribute:
25
bytesSent:
26
alias: tomcat.bytes_sent
27
metric_type: counter
28
bytesReceived:
29
alias: tomcat.bytes_rcvd
30
metric_type: counter
31
errorCount:
32
alias: tomcat.error_count
33
metric_type: counter
34
requestCount:
35
alias: tomcat.request_count
36
metric_type: counter
37
maxTime:
38
alias: tomcat.max_time
39
metric_type: gauge
40
processingTime:
41
alias: tomcat.processing_time
42
metric_type: counter
43
- include:
44
j2eeType: Servlet
45
attribute:
46
processingTime:
47
alias: tomcat.servlet.processing_time
48
metric_type: counter
49
errorCount:
50
alias: tomcat.servlet.error_count
51
metric_type: counter
52
requestCount:
53
alias: tomcat.servlet.request_count
54
metric_type: counter
55
- include:
56
type: Cache
57
attribute:
58
accessCount:
59
alias: tomcat.cache.access_count
60
metric_type: counter
61
hitsCounts:
62
alias: tomcat.cache.hits_count
63
metric_type: counter
64
- include:
65
type: JspMonitor
66
attribute:
67
jspCount:
68
alias: tomcat.jsp.count
69
metric_type: counter
70
jspReloadCount:
71
alias: tomcat.jsp.reload_count
72
metric_type: counter
Copied!
See the JMX Check documentation for a list of configuration options usable by all JMX-based checks. The page also describes how the Agent tags JMX metrics.
Restart the Agent to start sending Tomcat metrics to StackState.
Configuration Options:
Option
Required
Description
user and password
No
Username and password
process_name_regex
No
Instead of specifying a host and port or jmx_url, the Agent can connect using the attach api. This requires the JDK to be installed and the path to tools.jar to be set.
tools_jar_path
No
Should be set when process_name_regex is set.
java_bin_path
No
Should be set if the Agent cannot find your java executable.
java_options
No
Java JVM options
trust_store_path and trust_store_password
No
Should be set if com.sun.management.jmxremote.ssl is set to true on the target JVM.
key_store_path and key_store_password
No
Should be set if com.sun.management.jmxremote.ssl.need.client.auth is set to true on the target JVM.
rmi_registry_ssl
No
Should be set to true if com.sun.management.jmxremote.registry.ssl is set to true on the target JVM.
The conf parameter is a list of dictionaries. Only 2 keys are allowed in this dictionary:
Key
Required
Description
include
Yes
A dictionary of filters. Any attribute that matches these filters are collected unless it also matches the "exclude" filters.
exclude
No
A dictionary of filters. Attributes that match these filters won't be collected.
For a given bean, metrics get tagged in the following manner:
1
mydomain:attr0=val0,attr1=val1
Copied!
Your metric is mydomain (or some variation depending on the attribute inside the bean) and has the tags attr0:val0, attr1:val1, domain:mydomain.
If you specify an alias in an include key that is formatted as camel case, it is converted to snake case. For example, MyMetricName is shown in StackState as my_metric_name.
See the sample tomcat.yaml for all available configuration options.
The attribute filter
The attribute filter accepts two types of values:
  • A dictionary whose keys are attributes names:
1
conf:
2
- include:
3
attribute:
4
maxThreads:
5
alias: tomcat.threads.max
6
metric_type: gauge
7
currentThreadCount:
8
alias: tomcat.threads.count
9
metric_type: gauge
10
bytesReceived:
11
alias: tomcat.bytes_rcvd
12
metric_type: counter
Copied!
For the case above, the metric aliases specified become the metric name in StackState. Also, the metric type can be specified as a gauge or counter. If you choose counter, a rate per second is computed for this metric.
  • A list of attributes names:
1
conf:
2
- include:
3
domain: org.apache.cassandra.db
4
attribute:
5
- BloomFilterDiskSpaceUsed
6
- BloomFilterFalsePositives
7
- BloomFilterFalseRatio
8
- Capacity
9
- CompressionRatio
10
- CompletedTasks
11
- ExceptionCount
12
- Hits
13
- RecentHitRate
Copied!
In that case:
  • The metric type is a gauge
  • The metric name is jmx.\[DOMAIN_NAME].\[ATTRIBUTE_NAME]
Here is another filtering example:
1
instances:
2
- host: 127.0.0.1
3
name: jmx_instance
4
port: 9999
5
​
6
init_config:
7
conf:
8
- include:
9
bean: org.apache.cassandra.metrics:type=ClientRequest,scope=Write,name=Latency
10
attribute:
11
- OneMinuteRate
12
- 75thPercentile
13
- 95thPercentile
14
- 99thPercentile
Copied!
1
conf:
2
- include:
3
domain: domain_name
4
bean:
5
- first_bean_name
6
- second_bean_name
Copied!

Log Collection

Tomcat uses by default the log4j logger. To activate the logging into a file and customize the log format edit the log4j.properties file in the $CATALINA_BASE/lib directory as follows:
1
log4j.rootLogger = INFO, CATALINA
2
​
3
# Define all the appenders
4
log4j.appender.CATALINA = org.apache.log4j.DailyRollingFileAppender
5
log4j.appender.CATALINA.File = /var/log/tomcat/catalina.log
6
log4j.appender.CATALINA.Append = true
7
​
8
# Roll-over the log once per day
9
log4j.appender.CATALINA.layout = org.apache.log4j.PatternLayout
10
log4j.appender.CATALINA.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %c{1}:%L - %m%n
11
​
12
log4j.appender.LOCALHOST = org.apache.log4j.DailyRollingFileAppender
13
log4j.appender.LOCALHOST.File = /var/log/tomcat/localhost.log
14
log4j.appender.LOCALHOST.Append = true
15
log4j.appender.LOCALHOST.layout = org.apache.log4j.PatternLayout
16
log4j.appender.LOCALHOST.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %c{1}:%L - %m%n
17
​
18
log4j.appender.MANAGER = org.apache.log4j.DailyRollingFileAppender
19
log4j.appender.MANAGER.File = /var/log/tomcat/manager.log
20
log4j.appender.MANAGER.Append = true
21
log4j.appender.MANAGER.layout = org.apache.log4j.PatternLayout
22
log4j.appender.MANAGER.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %c{1}:%L - %m%n
23
​
24
log4j.appender.HOST-MANAGER = org.apache.log4j.DailyRollingFileAppender
25
log4j.appender.HOST-MANAGER.File = /var/log/tomcat/host-manager.log
26
log4j.appender.HOST-MANAGER.Append = true
27
log4j.appender.HOST-MANAGER.layout = org.apache.log4j.PatternLayout
28
log4j.appender.HOST-MANAGER.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %c{1}:%L - %m%n
29
​
30
log4j.appender.CONSOLE = org.apache.log4j.ConsoleAppender
31
log4j.appender.CONSOLE.layout = org.apache.log4j.PatternLayout
32
log4j.appender.CONSOLE.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %c{1}:%L - %m%n
33
​
34
# Configure which loggers log to which appenders
35
log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost] = INFO, LOCALHOST
36
log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager] =\
37
INFO, MANAGER
38
log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager] =\
39
INFO, HOST-MANAGER
Copied!
Check Tomcat logging documentation for more information about Tomcat logging capabilities.
  • Collecting logs is disabled by default in the StackState Agent, enable it in your stackstate.yaml file with:
    1
    logs_enabled: true
    Copied!
  • Add this configuration block to your tomcat.d/conf.yaml file to start collecting your Tomcat Logs:
    1
    logs:
    2
    - type: file
    3
    path: /var/log/tomcat/*.log
    4
    source: tomcat
    5
    service: myapp
    6
    #To handle multi line that starts with yyyy-mm-dd use the following pattern
    7
    #log_processing_rules:
    8
    # - type: multi_line
    9
    # name: log_start_with_date
    10
    # pattern: \d{4}\-(0?[1-9]|1[012])\-(0?[1-9]|[12][0-9]|3[01])
    Copied!
  • Change the path and service parameter values and configure them for your environment. See the sample tomcat.yaml for all available configuration options.
  • Restart the Agent.

Validation

Run the Agent's status subcommand and look for tomcat under the Checks section.

Data Collected

Metrics

See metadata.csv for a list of metrics provided by this check.

Events

The Tomcat check does not include any events.

Service Checks

tomcat.can_connect Returns CRITICAL if the Agent is unable to connect to and collect metrics from the monitored Tomcat instance. Returns OK otherwise.

Troubleshooting

Commands to view the metrics that are available:

  • List attributes that match at least one of your instance configurations:
    sudo /etc/init.d/stackstate-agent jmx list_matching_attributes
  • List attributes that match one of your instance configurations but that are not collected because it would exceed the number of metrics that can be collected:
    sudo /etc/init.d/stackstate-agent jmx list_limited_attributes
  • List attributes that are actually collected by your current instance configurations:
    sudo /etc/init.d/stackstate-agent jmx list_collected_attributes
  • List attributes that don't match any of your instance configurations:
    sudo /etc/init.d/stackstate-agent jmx list_not_matching_attributes
  • List every attribute available that has a type supported by JMXFetch:
    sudo /etc/init.d/stackstate-agent jmx list_everything
  • Start the collection of metrics based on your current configuration and display them in the console:
    sudo /etc/init.d/stackstate-agent jmx collect
Last modified 20d ago