Tomcat本地查看堆内存信息:
[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”]
一个完整的zabbix item填写方式如下,不同内容填写不同的键值即可:
3.2.内存池eden space:
Tomcat本地查看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:
Tomcat本地查看Survivor space区域:
java -jar cmdline-jmxclient-0.10.3.jar - 127.0.0.1:8090 java.lang:type=MemoryPool,name=PS\ Survivor\ Space Usage
zabbix监控Survivor 键值:
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:
Tomcat本地查看old gen区域使用:
java -jar cmdline-jmxclient-0.10.3.jar - 127.0.0.1:8090 java.lang:name=PS\ Old\ Gen,type=MemoryPool Usage
zabbix监控old gen键值:
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.非堆内存:
Tomcat 本地查看非堆内存使用:
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:
Tomcat 本地查看meta space区域使用:
java -jar cmdline-jmxclient-0.10.3.jar - 127.0.0.1:8090 java.lang:type=MemoryPool,name=Metaspace Usage
zabbix监控mete space区域键值
jmx[“java.lang:type=MemoryPool,name=Metaspace”,Usage.committed]
jmx[“java.lang:type=MemoryPool,name=Metaspace”,Usage.used]
3.7.内存池code cache:
Tomcat 本地查看code cache区域使用:
java -jar cmdline-jmxclient-0.10.3.jar - 127.0.0.1:8090 java.lang:type=MemoryPool,name=Code\ Cache Usage
zabbix监控code cache区域使用:
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:
Tomcat 本地查看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
zabbix监控 compressed class space区域使用键值:
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.类加载:
Tomcat本地查看类加载信息:
加载总数: 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
Zabbix监控类加载键值:
加载总数: jmx[“java.lang:type=ClassLoading”,“TotalLoadedClassCount”]
已加载: jmx[“java.lang:type=ClassLoading”,“LoadedClassCount”]
已卸载: jmx[“java.lang:type=ClassLoading”,“UnloadedClassCount”]
3.10.java线程:
tomcat本地查看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
Zabbix监控java线程键值:
总开启线程: jmx[“java.lang:type=Threading”,“TotalStartedThreadCount”]
活动线程: jmx[“java.lang:type=Threading”,“ThreadCount”]
线程峰值: jmx[“java.lang:type=Threading”,“PeakThreadCount”]
3.11.tomcat线程:
本地查看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
Zabbix监控tomcat线程键值:
最大线程: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.网络流量:
Tomcat本地查看接收的字节:
接收的字节: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
Zabbix监控tomcat接受字节键值:
接收的字节:jmx["Catalina:type=GlobalRequestProcessor,name=“http-nio-8080"”,bytesReceived]
发送的字节:jmx["Catalina:type=GlobalRequestProcessor,name=“http-nio-8080"”,bytesSent]
3.13.tomcat请求,出错请求:
tomcat本地查看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
zabbix监控tomcat请求数:
tomcat请求数: jmx["Catalina:type=GlobalRequestProcessor,name=“http-nio-8080"”,requestCount]
tomcat出错请求:jmx["Catalina:type=GlobalRequestProcessor,name=“http-nio-8080"”,errorCount]
4.问题的解答
最近有网友联系我说,看着我的博文搭建完了环境,获取不到数据,我帮助排查了一下,找到了问题所在,特此记录。
网友的报错如下:
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和属性的方法。
(1)通过jconsole查看:
(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
然后我要获取Eden Space的所有属性信息方式如下:(一些特殊字符需要转义)
[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)