Tomcat
Tomcat metrics can be collected by using DDTrace. The flow of the collected data is as follows: Tomcat -> DDTrace -> DataKit(StatsD).
You can see that DataKit has already integrated the StatsD server, and DDTrace collects Tomcat metric data and reports it to DataKit using StatsD protocol.
Configuration¶
Preconditions¶
- Already tested Tomcat version:
- 11.0.0
- 10.1.10
- 9.0.76
- 8.5.90
DDtrace Configuration¶
-
Download
dd-java-agent.jar, see here; -
DataKit configuration:
See the configuration of StatsD.
Restart DataKit to make configuration take effect.
- Tomcat configuration:
Create the file setenv.sh under /usr/local/tomcat/bin and give it execute permission, then write the following:
export CATALINA_OPTS="-javaagent:dd-java-agent.jar \
-Ddd.jmxfetch.enabled=true \
-Ddd.jmxfetch.statsd.host=${DATAKIT_HOST} \
-Ddd.jmxfetch.statsd.port=${DATAKIT_STATSD_HOST} \
-Ddd.jmxfetch.tomcat.enabled=true"
The parameters are described below:
javaagent: Fill in the full path todd-java-agent.jar;Ddd.jmxfetch.enabled: Fill intrue, which means the DDTrace collection function is enabled;Ddd.jmxfetch.statsd.host: Fill in the network address that DataKit listens to. No port number is included;Ddd.jmxfetch.statsd.port: Fill in the port number that DataKit listens to. Usually8125, as determined by the DataKit side configuration;Ddd.jmxfetch.tomcat.enabled: Fill intrue, which means the Tomcat collect function of DDTrace is enabled. When enabled, the metrics set namedtomcatwill showing up;
Restart DataKit to make configuration take effect.
Metric¶
There will be two metrics set, one for JVM's metrics, and the other for tomcat, only tomcat is shown below.
For all of the following data collections, the global election tags will be added automatically, we can add extra tags in [inputs.tomcat.tags] if needed:
tomcat¶
| Tags & Fields | Description |
|---|---|
| host ( tag) |
Hostname. |
| instance ( tag) |
Instance. |
| jmx_domain ( tag) |
JMX domain. |
| metric_type ( tag) |
Metric type. |
| name ( tag) |
Name. |
| runtime-id ( tag) |
Runtime ID. |
| service ( tag) |
Service name. |
| type ( tag) |
Type. |
| bytes_rcvd | Bytes per second received by all request processors. Type: float | (gauge) Unit: count |
| bytes_sent | Bytes per second sent by all the request processors. Type: float | (gauge) Unit: count |
| cache_access_count | The number of accesses to the cache per second. Type: float | (gauge) Unit: count |
| cache_hits_count | The number of cache hits per second. Type: float | (gauge) Unit: count |
| error_count | The number of errors per second on all request processors. Type: float | (gauge) Unit: count |
| jsp_count | The number of JSPs per second that have been loaded in the web module. Type: float | (gauge) Unit: count |
| jsp_reload_count | The number of JSPs per second that have been reloaded in the web module. Type: float | (gauge) Unit: count |
| max_time | The longest request processing time (in milliseconds). Type: float | (gauge) Unit: count |
| processing_time | The sum of request processing times across all requests handled by the request processors (in milliseconds) per second. Type: float | (gauge) Unit: count |
| request_count | The number of requests per second across all request processors. Type: float | (gauge) Unit: count |
| servlet_error_count | The number of erroneous requests received by the Servlet per second. Type: float | (gauge) Unit: count |
| servlet_processing_time | The sum of request processing times across all requests to the Servlet (in milliseconds) per second. Type: float | (gauge) Unit: count |
| servlet_request_count | The number of requests received by the Servlet per second. Type: float | (gauge) Unit: count |
| string_cache_access_count | The number of accesses to the string cache per second. Type: float | (gauge) Unit: count |
| string_cache_hit_count | The number of string cache hits per second. Type: float | (gauge) Unit: count |
| threads_busy | The number of threads that are in use. Type: float | (gauge) Unit: count |
| threads_count | The number of threads managed by the thread pool. Type: float | (gauge) Unit: count |
| threads_max | The maximum number of allowed worker threads. Type: float | (gauge) Unit: count |
| web_cache_hit_count | The number of web resource cache hits per second. Type: float | (gauge) Unit: count |
| web_cache_lookup_count | The number of lookups to the web resource cache per second. Type: float | (gauge) Unit: count |
Log Collection¶
Info
Log collection only supports log collection on installed DataKit hosts.
If you want to collect Tomcat logs, you need to enable the file collection function. You can write the absolute path to the Tomcat log file in logging.conf. For example:
After the changes are made, restart DataKit to make the configuration take effect.
Field Description¶
- Access Log
Log sample:
0:0:0:0:0:0:0:1 - admin [24/Feb/2015:15:57:10 +0530] "GET /manager/images/tomcat.gif HTTP/1.1" 200 2066
The list of cut fields is as follows:
| Field Name | Field Value | Description |
|---|---|---|
| time | 1424773630000000000 | Time when the log was generated |
| status | OK | Log level |
| client_ip | 0:0:0:0:0:0:0:1 | Mobile ip |
| http_auth | admin | Authorized users authenticated by HTTP Basic |
| http_method | GET | HTTP methods |
| http_url | /manager/images/tomcat.gif | Client request address |
| http_version | 1.1 | HTTP Protocol Version |
| status_code | 200 | HTTP status code |
| bytes | 2066 | Number of bytes of HTTP response body |
- Catalina / Host-manager / Localhost / Manager Log
log example:
06-Sep-2021 22:33:30.513 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xmx256m
the list of cut fields is as follows:
| Field Name | Field Value | Description |
|---|---|---|
| time | 1630938810513000000 | Time when the log was generated |
| status | INFO | Log level |
| thread_name | main | Thread name |
| report_source | org.apache.catalina.startup.VersionLoggerListener.log | ClassName.MethodName |
| msg | Command line argument: -Xmx256m | Message |
Jolokia¶
Deprecated, removed in new version {#jolokia}
Config¶
Preconditions¶
- Already tested version:
- 9
- 8
Download Jolokia, rename it to jolokia.war, and place it in tomcat's webapps directory. You can also get the jolokia war package from the data directory under the DataKit installation directory. Edit tomcat-users.xml in tomcat's conf directory and add the user whose role is jolokia.
Take apache-tomcat-9.0.45 as an example (the username and password of the jolokia user in the example must be modified) :
$ cd apache-tomcat-9.0.45/
$ export tomcat_dir=`pwd`
$ wget https://search.maven.org/remotecontent?filepath=org/jolokia/jolokia-war/1.6.2/jolokia-war-1.6.2.war \
-O $tomcat_dir/webapps/jolokia.war
$ vim $tomcat_dir/conf/tomcat-users.xml
37 <!--
38 <role rolename="tomcat"/>
39 <role rolename="role1"/>
40 <user username="tomcat" password="<must-be-changed>" roles="tomcat"/>
41 <user username="both" password="<must-be-changed>" roles="tomcat,role1"/>
42 <user username="role1" password="<must-be-changed>" roles="role1"/>
43 -->
44 <role rolename="jolokia"/>
45 <user username="jolokia_user" password="secPassWd@123" roles="jolokia"/>
46
47 </tomcat-users>
$ $tomcat_dir/bin/startup.sh
...
Tomcat started.
Go to http://localhost:8080/jolokia to see if the configuration was successful.
Configuration¶
Go to the conf.d/tomcat directory under the DataKit installation directory, copy tomcat.conf.sample and name it tomcat.conf. Examples are as follows:
[[inputs.tomcat]]
### Tomcat user(rolename="jolokia"). For example:
# username = "jolokia_user"
# password = "secPassWd@123"
# response_timeout = "5s"
urls = ["http://localhost:8080/jolokia"]
### Optional TLS config
# tls_ca = "/var/private/ca.pem"
# tls_cert = "/var/private/client.pem"
# tls_key = "/var/private/client-key.pem"
# insecure_skip_verify = false
### Monitor Interval
# interval = "15s"
## Set true to enable election
# election = true
# [inputs.tomcat.log]
# files = []
# #grok pipeline script path
# pipeline = "tomcat.p"
[inputs.tomcat.tags]
# some_tag = "some_value"
# more_tag = "some_other_value"
# ...
### Tomcat metrics
[[inputs.tomcat.metric]]
name = "tomcat_global_request_processor"
mbean = '''Catalina:name="*",type=GlobalRequestProcessor'''
paths = ["requestCount","bytesReceived","bytesSent","processingTime","errorCount"]
tag_keys = ["name"]
[[inputs.tomcat.metric]]
name = "tomcat_jsp_monitor"
mbean = "Catalina:J2EEApplication=*,J2EEServer=*,WebModule=*,name=jsp,type=JspMonitor"
paths = ["jspReloadCount","jspCount","jspUnloadCount"]
tag_keys = ["J2EEApplication","J2EEServer","WebModule"]
[[inputs.tomcat.metric]]
name = "tomcat_thread_pool"
mbean = "Catalina:name=\"*\",type=ThreadPool"
paths = ["maxThreads","currentThreadCount","currentThreadsBusy"]
tag_keys = ["name"]
[[inputs.tomcat.metric]]
name = "tomcat_servlet"
mbean = "Catalina:J2EEApplication=*,J2EEServer=*,WebModule=*,j2eeType=Servlet,name=*"
paths = ["processingTime","errorCount","requestCount"]
tag_keys = ["name","J2EEApplication","J2EEServer","WebModule"]
[[inputs.tomcat.metric]]
name = "tomcat_cache"
mbean = "Catalina:context=*,host=*,name=Cache,type=WebResourceRoot"
paths = ["hitCount","lookupCount"]
tag_keys = ["context","host"]
tag_prefix = "tomcat_"
The collector can now be turned on by ConfigMap Injection Collector Configuration.
Measurement¶
For all of the following data collections, a global tag named host is appended by default (the tag value is the host name of the DataKit), or other tags can be specified in the configuration through [inputs.tomcat.tags]:
tomcat_global_request_processor¶
| Tags & Fields | Description |
|---|---|
| host ( tag) |
System hostname. |
| jolokia_agent_url ( tag) |
Jolokia agent url. |
| name ( tag) |
Protocol handler name. |
| bytesReceived | Amount of data received, in bytes. Type: int | (gauge) Unit: count |
| bytesSent | Amount of data sent, in bytes. Type: int | (gauge) Unit: count |
| errorCount | Number of errors. Type: int | (gauge) Unit: count |
| processingTime | Total time to process the requests. Type: int | (gauge) Unit: time,ms |
| requestCount | Number of requests processed. Type: int | (gauge) Unit: count |
tomcat_jsp_monitor¶
| Tags & Fields | Description |
|---|---|
| J2EEApplication ( tag) |
J2EE Application. |
| J2EEServer ( tag) |
J2EE Servers. |
| WebModule ( tag) |
Web Module. |
| host ( tag) |
System hostname. |
| jolokia_agent_url ( tag) |
Jolokia agent url. |
| jspCount | The number of JSPs that have been loaded into a webapp. Type: int | (gauge) Unit: count |
| jspReloadCount | The number of JSPs that have been reloaded. Type: int | (gauge) Unit: count |
| jspUnloadCount | The number of JSPs that have been unloaded. Type: int | (gauge) Unit: count |
tomcat_thread_pool¶
| Tags & Fields | Description |
|---|---|
| host ( tag) |
System hostname. |
| jolokia_agent_url ( tag) |
Jolokia agent url. |
| name ( tag) |
Protocol handler name. |
| currentThreadCount | CurrentThreadCount. Type: int | (gauge) Unit: count |
| currentThreadsBusy | CurrentThreadsBusy. Type: int | (gauge) Unit: count |
| maxThreads | MaxThreads. Type: float | (gauge) Unit: count |
tomcat_servlet¶
| Tags & Fields | Description |
|---|---|
| J2EEApplication ( tag) |
J2EE Application. |
| J2EEServer ( tag) |
J2EE Server. |
| WebModule ( tag) |
Web Module. |
| host ( tag) |
System hostname. |
| jolokia_agent_url ( tag) |
Jolokia agent url. |
| name ( tag) |
Name |
| errorCount | Error count. Type: int | (gauge) Unit: count |
| processingTime | Total execution time of the Servlet's service method. Type: int | (gauge) Unit: time,ms |
| requestCount | Number of requests processed by this wrapper. Type: int | (gauge) Unit: count |
tomcat_cache¶
| Tags & Fields | Description |
|---|---|
| host ( tag) |
System hostname. |
| jolokia_agent_url ( tag) |
Jolokia agent url. |
| tomcat_context ( tag) |
Tomcat context. |
| tomcat_host ( tag) |
Tomcat host. |
| hitCount | The number of requests for resources that were served from the cache. Type: int | (gauge) Unit: count |
| lookupCount | The number of requests for resources. Type: int | (gauge) Unit: count |
Log Collection¶
Info
Log collection only supports log collection on installed DataKit hosts.
To collect Tomcat logs, open files in tomcat.conf and write to the absolute path of the Tomcat log file. For example:
After log collection is turned on, logs with tomcat as the log source will be generated by default.
Field Description¶
- Access Log
Log sample:
0:0:0:0:0:0:0:1 - admin [24/Feb/2015:15:57:10 +0530] "GET /manager/images/tomcat.gif HTTP/1.1" 200 2066
The list of cut fields is as follows:
| Field Name | Field Value | Description |
|---|---|---|
| time | 1424773630000000000 | Time when the log was generated |
| status | OK | Log level |
| client_ip | 0:0:0:0:0:0:0:1 | Mobile ip |
| http_auth | admin | Authorized users authenticated by HTTP Basic |
| http_method | GET | HTTP methods |
| http_url | /manager/images/tomcat.gif | Client request address |
| http_version | 1.1 | HTTP Protocol Version |
| status_code | 200 | HTTP status code |
| bytes | 2066 | Number of bytes of HTTP response body |
- Catalina / Host-manager / Localhost / Manager Log
Log example:
06-Sep-2021 22:33:30.513 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xmx256m
the list of cut fields is as follows:
| Field Name | Field Value | Description |
|---|---|---|
| time | 1630938810513000000 | Time when the log was generated |
| status | INFO | Log level |
| thread_name | main | Thread name |
| report_source | org.apache.catalina.startup.VersionLoggerListener.log | ClassName.MethodName |
| msg | Command line argument: -Xmx256m | Message |