Tomcat
可以使用 DDTrace 可以采集 Tomcat 指标。采集数据流向如下:Tomcat -> DDTrace -> DataKit(StatsD)。
可以看到 DataKit 已经集成了 StatsD 的服务端,DDTrace 采集 Tomcat 的数据后使用 StatsD 的协议报告给了 DataKit。
配置¶
前置条件¶
-
已测试的 Tomcat 版本:
- 11.0.0
- 10.1.10
- 9.0.76
- 8.5.90
配置¶
在 /usr/local/tomcat/bin 下创建文件 setenv.sh 并赋予执行权限,再写入以下内容:
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"
参数说明如下:
javaagent: 这个填写dd-java-agent.jar的完整路径;Ddd.jmxfetch.enabled: 填true, 表示开启 DDTrace 的采集功能;Ddd.jmxfetch.statsd.host: 填写 DataKit 监听的网络地址。不含端口号;Ddd.jmxfetch.statsd.port: 填写 DataKit 监听的端口号。一般为8125,由 DataKit 侧的配置决定;Ddd.jmxfetch.tomcat.enabled: 填true, 表示开启 DDTrace 的 Tomcat 采集功能。开启后会多出名为tomcat的指标集;
重启 Tomcat 使配置生效。
指标¶
会产生两个指标集,一个是 JVM 的指标集,另一个是 tomcat 的指标集,以下只展示 tomcat 的指标集。
以下所有数据采集,默认会追加名为 host 的全局 tag(tag 值为 DataKit 所在主机名),也可以在配置中通过 [inputs.statsd.tags] 指定其它标签:
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 |
日志¶
Info
日志采集仅支持采集已安装 DataKit 主机上的日志
如需采集 Tomcat 的日志,需开启文件采集功能。可在 logging.conf 中写入 Tomcat 日志文件的绝对路径。比如:
修改完成后,重启 DataKit 使配置生效。
字段说明¶
- Access Log
日志示例:
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
切割后的字段列表如下:
| 字段名 | 字段值 | 说明 |
|---|---|---|
| time | 1424773630000000000 | 日志产生的时间 |
| status | OK | 日志等级 |
| client_ip | 0:0:0:0:0:0:0:1 | 客户端 ip |
| http_auth | admin | 通过 HTTP Basic 认证的授权用户 |
| http_method | GET | HTTP 方法 |
| http_url | /manager/images/tomcat.gif | 客户端请求地址 |
| http_version | 1.1 | HTTP 协议版本 |
| status_code | 200 | HTTP 状态码 |
| bytes | 2066 | HTTP 响应 body 的字节数 |
- Catalina / Host-manager / Localhost / Manager Log
日志示例:
06-Sep-2021 22:33:30.513 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xmx256m
切割后的字段列表如下:
| 字段名 | 字段值 | 说明 |
|---|---|---|
time |
1630938810513000000 |
日志产生的时间 |
status |
INFO |
日志等级 |
thread_name |
main |
线程名 |
report_source |
org.apache.catalina.startup.VersionLoggerListener.log |
ClassName.MethodName |
msg |
Command line argument: -Xmx256m |
消息 |
Jolokia¶
已废弃,新版本中已移除。
配置¶
前置条件¶
-
已测试的版本:
- 9
- 8
-
下载 Jolokia,重命名为
jolokia.war,并放置于 Tomcat 的 webapps 目录下。也可从 DataKit 的安装目录下的 data 目录下获取 jolokia.war 包 - 编辑 Tomcat 的 conf 目录下的 tomcat-users.xml,增加
role为jolokia的用户。
以 apache-tomcat-9.0.45 为例:
注意:示例中 Jolokia 的
username和password请务必修改
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
<!--
<role rolename="tomcat"/>
<role rolename="role1"/>
<user username="tomcat" password="<must-be-changed>" roles="tomcat"/>
<user username="both" password="<must-be-changed>" roles="tomcat,role1"/>
<user username="role1" password="<must-be-changed>" roles="role1"/>
-->
<role rolename="jolokia"/>
<user username="jolokia_user" password="secPassWd@123" roles="jolokia"/>
</tomcat-users>
启动脚本
前往 http://localhost:8080/jolokia 查看是否配置成功
采集器配置¶
进入 DataKit 安装目录下的 conf.d/samples 目录,复制 tomcat.conf.sample 并命名为 tomcat.conf。示例如下:
[[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_"
目前可以通过 ConfigMap 方式注入采集器配置来开启采集器。
指标¶
以下所有数据采集,默认会追加名为 host 的全局 tag(tag 值为 DataKit 所在主机名),也可以在配置中通过 [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 |
日志¶
Info
日志采集仅支持采集已安装 DataKit 主机上的日志
如需采集 Tomcat 的日志,可在 tomcat.conf 中 将 files 打开,并写入 Tomcat 日志文件的绝对路径。比如:
开启日志采集以后,默认会产生日志来源(source)为 tomcat 的日志。
字段说明¶
- Access Log
日志示例:
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
切割后的字段列表如下:
| 字段名 | 字段值 | 说明 |
|---|---|---|
| time | 1424773630000000000 | 日志产生的时间 |
| status | OK | 日志等级 |
| client_ip | 0:0:0:0:0:0:0:1 | 客户端 ip |
| http_auth | admin | 通过 HTTP Basic 认证的授权用户 |
| http_method | GET | HTTP 方法 |
| http_url | /manager/images/tomcat.gif | 客户端请求地址 |
| http_version | 1.1 | HTTP 协议版本 |
| status_code | 200 | HTTP 状态码 |
| bytes | 2066 | HTTP 响应 body 的字节数 |
- Catalina / Host-manager / Localhost / Manager Log
日志示例:
06-Sep-2021 22:33:30.513 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xmx256m
切割后的字段列表如下:
| 字段名 | 字段值 | 说明 |
|---|---|---|
time |
1630938810513000000 |
日志产生的时间 |
status |
INFO |
日志等级 |
thread_name |
main |
线程名 |
report_source |
org.apache.catalina.startup.VersionLoggerListener.log |
ClassName.MethodName |
msg |
Command line argument: -Xmx256m |
消息 |