其他
使用 zabbix 监控 tomcat(包含jvm监控)
点击上方“民工哥技术之路”选择“星标”
每天10点为你分享不一样的干货
1.前言:
zabbix官方提供的jvm和tomcat监控模版,存在item书写格式的坑,导致很多内容无法获取到监控。 网友写的zabbix监控java文章,99%就只有环境的搭建,没有zabbix item键值,所以环境监控上了,item键值不知道怎么写。
堆内存内存池:新生代(eden space),survivor space,老年代(old gen)的内存使用状态;
非堆内存内存池:代码缓存(Code cache),元空间(meta space),压缩类空间(compressed class space);
类加载:加载总数,已加载,已卸载。
Java线程:总开启线程,活动线程,线程峰值。
Tomcat网络流量统计:包括进流量统计,出流量统计;
Tomcat线程:包括最大线程数,当前线程数,当前繁忙线程数。
2.监控环境搭建
[root@tomcat-01 ~]# /usr/local/tomcat/bin/version.sh
Server version: Apache Tomcat/8.0.23
Server built: May 19 2015 14:58:38 UTC
Server number: 8.0.23.0
OS Name: Linux
OS Version: 2.6.32-573.22.1.el6.x86_64
Architecture: amd64
JVM Version: 1.8.0_65-b17
JVM Vendor: Oracle Corporation
2.1.Server端配置
[root@zabbix ~]# vim /etc/zabbix/zabbix_java_gateway.conf
LISTEN_IP="192.168.10.3"
LISTEN_PORT=10052
PID_FILE="/var/run/zabbix/zabbix_java.pid"
START_POLLERS=5
修改zabbix-server配置文件
[root@zabbix ~]# vim /etc/zabbix/zabbix_server.conf
JavaGateway=192.168.10.3
JavaGatewayPort=10052
StartJavaPollers=5
启动zabbix-java-gateway服务
[root@zabbix ~]# /etc/init.d/zabbix-java-gateway start
2.2.Tomcat服务器配置
wget -O /usr/local/tomcat/lib/catalina-jmx-remote.jar http://archive.apache.org/dist/tomcat/tomcat-8/v8.0.23/bin/extras/catalina-jmx-remote.jar
2、修改catalina.sh添加如下内容
CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=8090
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false"
(2)本地执行如下命令查看tomcat的堆内存信息
[root@tomcat-01 ~]# java -jar /root/cmdline-jmxclient-0.10.3.jar - 127.0.0.1:8090 java.lang:type=Memory HeapMemoryUsage
11/04/2016 15:23:16 +0800 org.archive.jmx.Client HeapMemoryUsage:
committed: 2146959360
init: 2147483648
max: 2146959360
used: 407611808
3.监控数据采集
3.1.堆内存
[root@tomcat-01 ~]# java -jar cmdline-jmxclient-0.10.3.jar controlRole:tomcat 127.0.0.1:8090 java.lang:type=Memory HeapMemoryUsage
11/04/2016 15:36:58 +0800 org.archive.jmx.Client HeapMemoryUsage:
committed: 2145910784
init: 2147483648
max: 2145910784
used: 741540536
zabbix监控堆内存键值:
堆内存最大值:jmx["java.lang:type=Memory","HeapMemoryUsage.max"]
已用堆内存:jmx["java.lang:type=Memory","HeapMemoryUsage.used"]
已提交堆内存:jmx["java.lang:type=Memory","HeapMemoryUsage.committed"]
3.2.内存池eden space:
java -jar cmdline-jmxclient-0.10.3.jar - 127.0.0.1:8090 java.lang:type=MemoryPool,name=PS\ Eden\ Space Usage
zabbix监控eden区域键值:
最大空间:jmx["java.lang:type=MemoryPool,name=PS Eden Space",Usage.max]
已用空间:jmx["java.lang:type=MemoryPool,name=PS Eden Space",Usage.used]
提交空间:jmx["java.lang:type=MemoryPool,name=PS Eden Space",Usage.committed]
3.3.内存池survivor space:
java -jar cmdline-jmxclient-0.10.3.jar - 127.0.0.1:8090 java.lang:type=MemoryPool,name=PS\ Survivor\ Space Usage
jmx["java.lang:type=MemoryPool,name=PS Survivor Space",Usage.committed]
jmx["java.lang:type=MemoryPool,name=PS Survivor Space",Usage.max]
jmx["java.lang:type=MemoryPool,name=PS Survivor Space",Usage.used]
3.4.内存池old gen:
java -jar cmdline-jmxclient-0.10.3.jar - 127.0.0.1:8090 java.lang:name=PS\ Old\ Gen,type=MemoryPool Usage
jmx["java.lang:type=MemoryPool,name=PS Old Gen",Usage.committed]
jmx["java.lang:type=MemoryPool,name=PS Old Gen",Usage.max]
jmx["java.lang:type=MemoryPool,name=PS Old Gen",Usage.used]
3.5.非堆内存:
java -jar cmdline-jmxclient-0.10.3.jar controlRole:tomcat 127.0.0.1:8090 java.lang:type=Memory NonHeapMemoryUsag1
zabbix监控非堆内存使用
1jmx["java.lang:type=Memory","NonHeapMemoryUsag.committed"]
jmx["java.lang:type=Memory","NonHeapMemoryUsag.used"]
3.6.内存池meta space:
java -jar cmdline-jmxclient-0.10.3.jar - 127.0.0.1:8090 java.lang:type=MemoryPool,name=Metaspace Usage
jmx["java.lang:type=MemoryPool,name=Metaspace",Usage.committed]
jmx["java.lang:type=MemoryPool,name=Metaspace",Usage.used]
3.7.内存池code cache:
java -jar cmdline-jmxclient-0.10.3.jar - 127.0.0.1:8090 java.lang:type=MemoryPool,name=Code\ Cache Usage
jmx["java.lang:type=MemoryPool,name=Code Cache",Usage.committed]
jmx["java.lang:type=MemoryPool,name=Code Cache",Usage.max]
jmx["java.lang:type=MemoryPool,name=Code Cache",Usage.used]
3.8.内存池compressed class space:
java -jar cmdline-jmxclient-0.10.3.jar - 127.0.0.1:8090 java.lang:type=MemoryPool,name=Compressed\ Class\ Space Usage
jmx["java.lang:type=MemoryPool,name=Compressed Class Space",Usage.committed]
jmx["java.lang:type=MemoryPool,name=Compressed Class Space",Usage.max]
jmx["java.lang:type=MemoryPool,name=Compressed Class Space",Usage.used]
3.9.类加载:
加载总数: java -jar cmdline-jmxclient-0.10.3.jar controlRole:tomcat 127.0.0.1:8090 java.lang:type=ClassLoading TotalLoadedClassCoun
已加载: java -jar cmdline-jmxclient-0.10.3.jar controlRole:tomcat 127.0.0.1:8090 java.lang:type=ClassLoading LoadedClassCount
已卸载: java -jar cmdline-jmxclient-0.10.3.jar controlRole:tomcat 127.0.0.1:8090 java.lang:type=ClassLoading UnloadedClassCount
加载总数: jmx["java.lang:type=ClassLoading","TotalLoadedClassCount"]
已加载: jmx["java.lang:type=ClassLoading","LoadedClassCount"]
已卸载: jmx["java.lang:type=ClassLoading","UnloadedClassCount"]
3.10.java线程:
总开启线程: java -jar cmdline-jmxclient-0.10.3.jar controlRole:tomcat 127.0.0.1:8090 java.lang:type=Threading TotalStartedThreadCount
活动线程: java -jar cmdline-jmxclient-0.10.3.jar controlRole:tomcat 127.0.0.1:8090 java.lang:type=Threading PeakThreadCount
线程峰值: java -jar cmdline-jmxclient-0.10.3.jar controlRole:tomcat 127.0.0.1:8090 java.lang:type=Threading PeakThreadCount
总开启线程: jmx["java.lang:type=Threading","TotalStartedThreadCount"]
活动线程: jmx["java.lang:type=Threading","ThreadCount"]
线程峰值: jmx["java.lang:type=Threading","PeakThreadCount"]
3.11.tomcat线程:
最大线程:java -jar cmdline-jmxclient-0.10.3.jar - 127.0.0.1:8090 Catalina:name=\"http-nio-8080\",type=ThreadPool maxThreads
当前线程:java -jar cmdline-jmxclient-0.10.3.jar - 127.0.0.1:8090 Catalina:name=\"http-nio-8080\",type=ThreadPool currentThreadCount
繁忙线程:java -jar cmdline-jmxclient-0.10.3.jar - 127.0.0.1:8090 Catalina:name=\"http-nio-8080\",type=ThreadPool currentThreadsBusy
最大线程:jmx["Catalina:type=ThreadPool,name=\"http-nio-8080\"",maxThreads]
当前线程:jmx["Catalina:type=ThreadPool,name=\"http-nio-8080\"",currentThreadCount]
繁忙线程 jmx["Catalina:type=ThreadPool,name=\"http-nio-8080\"",currentThreadsBusy]
3.12.网络流量:
接收的字节:java -jar cmdline-jmxclient-0.10.3.jar - 127.0.0.1:8090 Catalina:name=\"http-nio-8080\",type=GlobalRequestProcessor bytesReceived
发送的字节:java -jar cmdline-jmxclient-0.10.3.jar - 127.0.0.1:8090 Catalina:name=\"http-nio-8080\",type=GlobalRequestProcessor bytesSent
接收的字节:jmx["Catalina:type=GlobalRequestProcessor,name=\"http-nio-8080\"",bytesReceived]
发送的字节:jmx["Catalina:type=GlobalRequestProcessor,name=\"http-nio-8080\"",bytesSent]
3.13.tomcat请求,出错请求:
tomcat请求数: java -jar cmdline-jmxclient-0.10.3.jar - 192.168.10.46:8090 Catalina:name=\"http-nio-8080\",type=GlobalRequestProcessor requestCount
tomcat出错请求: java -jar cmdline-jmxclient-0.10.3.jar - 192.168.10.46:8090 Catalina:name=\"http-nio-8080\",type=GlobalRequestProcessor errorCount
tomcat请求数: jmx["Catalina:type=GlobalRequestProcessor,name=\"http-nio-8080\"",requestCount]
tomcat出错请求:jmx["Catalina:type=GlobalRequestProcessor,name=\"http-nio-8080\"",errorCount]
# java -jar /root/cmdline-jmxclient-0.10.3.jar - 127.0.0.1:9080 java.lang:type=MemoryPool,name=PS\ Eden\ Space Usag
11/11/2016 10:03:37 +0800
org.archive.jmx.Client java.lang:name=PS Eden Space,type=MemoryPool is not a registered bean
4.1.解决思路
如果你使用命令行监控获取不到数据,那么就先使用jconsole看看有没有数据, 如果jconsole有数据,那么就往下看,反之检查你的环境。 如果jconsole有数据,但是命令行没有数据,那么就是Mbean的Object Name或者属性有问题,网友都是复制我的,但是自己本地环境和我的环境不一样所以导致获取不到数据,查询自己的本地Mbean方法有两种,分别是图形和命令行,网友的报错说事自己的Eden Space空间有问题,那么我就贴出来查看本地内存池的Object Name和属性的方法。
(2)通过命令行查看:直接使用java -jar cmdline-jmxclient-0.10.3.jar – 127.0.0.1:8090命令可以获取所有的Mbean信息,输出太多这里就不贴输出结果了。我通过grep命令获取所有内存池的监控信息方式如下。
[root@tomcat-01 ~]# java -jar cmdline-jmxclient-0.10.3.jar - 127.0.0.1:8090 | grep MemoryPool
java.lang:name=Compressed Class Space,type=MemoryPool
java.lang:name=Metaspace,type=MemoryPool
java.lang:name=PS Old Gen,type=MemoryPool
java.lang:name=PS Eden Space,type=MemoryPool
java.lang:name=PS Survivor Space,type=MemoryPool
java.lang:name=Code Cache,type=MemoryPool
[root@tomcat-01 ~]# java -jar cmdline-jmxclient-0.10.3.jar - 127.0.0.1:8090 java.lang:name=PS\ Eden\ Space,type=MemoryPool
Attributes:
Usage: Usage (type=javax.management.openmbean.CompositeData)
PeakUsage: PeakUsage (type=javax.management.openmbean.CompositeData)
MemoryManagerNames: MemoryManagerNames (type=[Ljava.lang.String;)
UsageThreshold: UsageThreshold (type=long)
UsageThresholdExceeded: UsageThresholdExceeded (type=boolean)
UsageThresholdCount: UsageThresholdCount (type=long)
UsageThresholdSupported: UsageThresholdSupported (type=boolean)
CollectionUsageThreshold: CollectionUsageThreshold (type=long)
CollectionUsageThresholdExceeded: CollectionUsageThresholdExceeded (type=boolean)
CollectionUsageThresholdCount: CollectionUsageThresholdCount (type=long)
CollectionUsage: CollectionUsage (type=javax.management.openmbean.CompositeData)
CollectionUsageThresholdSupported: CollectionUsageThresholdSupported (type=boolean)
Valid: Valid (type=boolean)
Name: Name (type=java.lang.String)
Type: Type (type=java.lang.String)
ObjectName: ObjectName (type=javax.management.ObjectName)
Operations:
resetPeakUsage: resetPeakUsage
Parameters 0, return type=void
[root@tomcat-01 ~]# java -jar cmdline-jmxclient-0.10.3.jar - 127.0.0.1:8090 java.lang:name=PS\ Eden\ Space,type=MemoryPool Usage
12/03/2016 08:33:58 +0800 org.archive.jmx.Client Usage:
committed: 712507392
init: 537395200
max: 712507392
used: 396006304
文章系作者原创投稿,作者:西门飞冰,一名90后it男,一直在北京工作,热爱运动,热爱冒险,热爱旅行。 原文:西门飞冰的博客-专注于Linux运维 » zabbix监控tomcat(包含jvm监控)。
在 民工哥技术之路 微信公众号对话框回复关键字:1024 可以获取一份最新整理的技术干货。
点击【阅读原文】和民工哥一起学技术、搞事情~~
点“在看”一定不能放弃啊