Skip to content

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 to dd-java-agent.jar;
  • Ddd.jmxfetch.enabled: Fill in true, 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. Usually 8125, as determined by the DataKit side configuration;
  • Ddd.jmxfetch.tomcat.enabled: Fill in true, which means the Tomcat collect function of DDTrace is enabled. When enabled, the metrics set named tomcat will 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:

 [inputs.statsd.tags]
  # some_tag = "some_value"
  # more_tag = "some_other_value"
  # ...

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 Per-second byte rate received by all request processors.
Type: float | (gauge)
Unit: digital,B
Tagged by: instance, jmx_domain, metric_type, name, runtime-id, service, type
bytes_sent Per-second byte rate sent by all request processors.
Type: float | (gauge)
Unit: digital,B
Tagged by: instance, jmx_domain, metric_type, name, runtime-id, service, type
cache_access_count The number of accesses to the cache per second.
Type: float | (gauge)
Unit: count
Tagged by: instance, jmx_domain, metric_type, name, runtime-id, service, type
cache_hits_count The number of cache hits per second.
Type: float | (gauge)
Unit: count
Tagged by: instance, jmx_domain, metric_type, name, runtime-id, service, type
error_count The number of errors per second on all request processors.
Type: float | (gauge)
Unit: count
Tagged by: instance, jmx_domain, metric_type, name, runtime-id, service, type
jsp_count The number of JSPs per second that have been loaded in the web module.
Type: float | (gauge)
Unit: count
Tagged by: instance, jmx_domain, metric_type, name, runtime-id, service, type
jsp_reload_count The number of JSPs per second that have been reloaded in the web module.
Type: float | (gauge)
Unit: count
Tagged by: instance, jmx_domain, metric_type, name, runtime-id, service, type
max_time Maximum request processing time observed during the interval.
Type: float | (gauge)
Unit: time,ms
Tagged by: instance, jmx_domain, metric_type, name, runtime-id, service, type
processing_time Per-second processing time accumulated across all request processors.
Type: float | (gauge)
Unit: time,ms
Tagged by: instance, jmx_domain, metric_type, name, runtime-id, service, type
request_count The number of requests per second across all request processors.
Type: float | (gauge)
Unit: count
Tagged by: instance, jmx_domain, metric_type, name, runtime-id, service, type
servlet_error_count The number of erroneous requests received by the Servlet per second.
Type: float | (gauge)
Unit: count
Tagged by: instance, jmx_domain, metric_type, name, runtime-id, service, type
servlet_processing_time Per-second servlet processing time accumulated across all requests.
Type: float | (gauge)
Unit: time,ms
Tagged by: instance, jmx_domain, metric_type, name, runtime-id, service, type
servlet_request_count The number of requests received by the Servlet per second.
Type: float | (gauge)
Unit: count
Tagged by: instance, jmx_domain, metric_type, name, runtime-id, service, type
string_cache_access_count The number of accesses to the string cache per second.
Type: float | (gauge)
Unit: count
Tagged by: instance, jmx_domain, metric_type, name, runtime-id, service, type
string_cache_hit_count The number of string cache hits per second.
Type: float | (gauge)
Unit: count
Tagged by: instance, jmx_domain, metric_type, name, runtime-id, service, type
threads_busy The number of threads that are in use.
Type: float | (gauge)
Unit: count
Tagged by: instance, jmx_domain, metric_type, name, runtime-id, service, type
threads_count The number of threads managed by the thread pool.
Type: float | (gauge)
Unit: count
Tagged by: instance, jmx_domain, metric_type, name, runtime-id, service, type
threads_max The maximum number of allowed worker threads.
Type: float | (gauge)
Unit: count
Tagged by: instance, jmx_domain, metric_type, name, runtime-id, service, type
web_cache_hit_count The number of web resource cache hits per second.
Type: float | (gauge)
Unit: count
Tagged by: instance, jmx_domain, metric_type, name, runtime-id, service, type
web_cache_lookup_count The number of lookups to the web resource cache per second.
Type: float | (gauge)
Unit: count
Tagged by: instance, jmx_domain, metric_type, name, runtime-id, service, type

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:

[[inputs.logging]]
  logfiles = [
    "/path_to_tomcat/logs/*",
  ]

  source = "tomcat"

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]:

 [inputs.tomcat.tags]
  # some_tag = "some_value"
  # more_tag = "some_other_value"
  # ...

tomcat_global_request_processor

Tags & Fields Description
host
(tag)
System hostname.
jolokia_agent_url
(tag)
Jolokia agent url.
name
(tag)
Protocol handler name.
bytesReceived Cumulative bytes received by the protocol handler.
Type: int | (count)
Unit: digital,B
Tagged by: jolokia_agent_url, name
bytesSent Cumulative bytes sent by the protocol handler.
Type: int | (count)
Unit: digital,B
Tagged by: jolokia_agent_url, name
errorCount Cumulative number of request-processing errors.
Type: int | (count)
Unit: count
Tagged by: jolokia_agent_url, name
processingTime Cumulative request processing time spent by the protocol handler.
Type: int | (count)
Unit: time,ms
Tagged by: jolokia_agent_url, name
requestCount Cumulative number of requests processed by the protocol handler.
Type: int | (count)
Unit: count
Tagged by: jolokia_agent_url, name

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 Cumulative number of JSPs loaded into the web application.
Type: int | (count)
Unit: count
Tagged by: J2EEApplication, J2EEServer, WebModule, jolokia_agent_url
jspReloadCount Cumulative number of JSP reloads.
Type: int | (count)
Unit: count
Tagged by: J2EEApplication, J2EEServer, WebModule, jolokia_agent_url
jspUnloadCount Cumulative number of JSP unloads.
Type: int | (count)
Unit: count
Tagged by: J2EEApplication, J2EEServer, WebModule, jolokia_agent_url

tomcat_thread_pool

Tags & Fields Description
host
(tag)
System hostname.
jolokia_agent_url
(tag)
Jolokia agent url.
name
(tag)
Protocol handler name.
currentThreadCount Current number of threads in the thread pool.
Type: int | (gauge)
Unit: count
Tagged by: jolokia_agent_url, name
currentThreadsBusy Current number of busy worker threads.
Type: int | (gauge)
Unit: count
Tagged by: jolokia_agent_url, name
maxThreads Maximum number of worker threads allowed in the thread pool.
Type: float | (gauge)
Unit: count
Tagged by: jolokia_agent_url, name

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 Cumulative number of servlet errors.
Type: int | (count)
Unit: count
Tagged by: J2EEApplication, J2EEServer, WebModule, jolokia_agent_url, name
processingTime Cumulative execution time of the servlet service method.
Type: int | (count)
Unit: time,ms
Tagged by: J2EEApplication, J2EEServer, WebModule, jolokia_agent_url, name
requestCount Cumulative number of requests processed by this servlet wrapper.
Type: int | (count)
Unit: count
Tagged by: J2EEApplication, J2EEServer, WebModule, jolokia_agent_url, name

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 Cumulative number of resource requests served from cache.
Type: int | (count)
Unit: count
Tagged by: jolokia_agent_url, tomcat_context, tomcat_host
lookupCount Cumulative number of resource cache lookup attempts.
Type: int | (count)
Unit: count
Tagged by: jolokia_agent_url, tomcat_context, tomcat_host

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:

  [inputs.tomcat.log]
    files = ["/path_to_tomcat/logs/*"]

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

Feedback

Is this page helpful? ×