tomcat default の http://$TOMCAT_HOST/manager/status/all?XML=true
https://tomcat.apache.org/tomcat-8.0-doc/manager-howto.html#Server_Status
上記urlに記載されている通り、tomcatデフォルトでも 基本ステータスは取得でき、例えば、私の環境では、次のように表示されます。
http://cent62.a5.jp:8080/manager/status/all?XML=true
Tomcat Status JVM: free:24493640 total:74842112 max:476446720 Memory Pools Name:Eden Space Type:Heap memory Initial:8388608 Committed:20709376 Maximum:131465216 Used:18697992 Name:Survivor Space Type:Heap memory Initial:1048576 Committed:2555904 Maximum:16384000 Used:379760 Name:Tenured Gen Type:Heap memory Initial:20971520 Committed:51576832 Maximum:328597504 Used:31270720 Name:Code Cache Type:Non-heap memory Initial:2555904 Committed:10158080 Maximum:251658240 Used:10010752 Name:Compressed Class Space Type:Non-heap memory Initial:0 Committed:2490368 Maximum:1073741824 Used:2265328 Name:Metaspace Type:Non-heap memory Initial:0 Committed:21364736 Maximum:-1 Used:20614728 Connector -- "ajp-nio-8009" threadInfo maxThreads:200 currentThreadCount:0 currentThreadsBusy:0 requestInfo maxTime:0 processingTime:0 requestCount:0 errorCount:0 bytesReceived:0 bytesSent:0 Stage Time B Sent B Recv Client VHost Request Connector -- "http-nio-8080" threadInfo maxThreads:200 currentThreadCount:25 currentThreadsBusy:1 requestInfo maxTime:12492 processingTime:1540034 requestCount:491 errorCount:355 bytesReceived:1921 bytesSent:2487646 Stage Time B Sent B Recv Client VHost Request R 0 0 0 ? ? ????? : : : : : : : S 12 8192 0 192.168.56.1 cent62.a5.jp GET/manager/status/all?XML=trueHTTP/1.1 : : : : : : :
Jolokia is remote JMX with JSON over HTTP.
https://jolokia.org/
今回、利用する Jolokia は、jsonでJMX(Java Management Extensions, MBean)にアクセスするもので、以降の手順で利用できます。
STEP1 JMX設定
step 1.1 server.xml の編集
「
$ vi /home/endo/local/tomcat8/conf/server.xml : <Server port="8005" shutdown="SHUTDOWN"> : <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" /> <Listener className="org.apache.catalina.mbeans.JmxRemoteLifecycleListener" rmiRegistryPortPlatform="10080" rmiServerPortPlatform="10081"/>
step 1.2 catalina-jmx-remote.jar の入手
$ /home/endo/local/apache-tomcat-8.0.21/lib/ $ wget http://archive.apache.org/dist/tomcat/tomcat-8/v8.0.21/bin/extras/catalina-jmx-remote.jar
step 1.3 startup.sh の編集
次のCATALINA_OPTS を追加して下さい
$ vi /home/endo/local/tomcat8/bin/startup.sh export CATALINA_OPTS="-Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=10080 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=cent62.a5.jp"
STEP2 jolokia の入手と動作確認
jolokia自体はwarで提供されている為、warを入手するだけで完了です。
https://jolokia.org/
cd /home/endo/local/tomcat8/webapps wget http://search.maven.org/remotecontent?filepath=org/jolokia/jolokia-war/1.2.3/jolokia-war-1.2.3.war mv jolokia-war-1.2.3.war jolokia.war
上記完了後、tomcatを再起動し、http://cent62.a5.jp:8080/jolokia へアクセスし、次のようなjsonが表示されれば、OKです。
{"request":{"type":"version"}, "value":{"agent":"1.2.3", "protocol":"7.2", "config":{"maxCollectionSize":"1000", "agentId":"192.168.56.102-30197-51428d6f-servlet", "debug":"false", "agentType":"servlet", "serializeException":"false", "detectorOptions":"{}", "dispatcherClasses":"org.jolokia.jsr160.Jsr160RequestDispatcher", "maxDepth":"15", "discoveryEnabled":"false", "canonicalNaming":"true", "historyMaxEntries":"10", "includeStackTrace":"true", "maxObjects":"0", "debugMaxEntries":"100"}, "info":{"product":"tomcat", "vendor":"Apache", "version":"8.0.21"}}, "timestamp":1430690476,"status":200}
STEP3 Jmx4Perl のinstall
http://search.cpan.org/dist/jmx4perl/
https://jolokia.org/tutorial.html
更に JMX::Jmx4Perl を使用すると、jolokia経由でJMXにアクセスできます。
# cpan install jmx4perl
JMX::Jmx4Perl をinstallすると、jmx4perl が合せてinstallされるので、これを実行すると、次のような結果をえることができます。
$ jmx4perl http://cent62.a5.jp:8080/jolokia Name: Apache Tomcat Vendor: Apache Version: 8.0.21 -------------------------------------------------------------------------------- Memory: Heap-Memory used : 35 MB Heap-Memory alloc : 41 MB Heap-Memory max : 454 MB NonHeap-Memory max : 0 MB Classes: Classes loaded : 3278 Classes total : 3287 Threads: Threads current : 27 Threads peak : 27 OS: CPU Arch : amd64 CPU OS : Linux 2.6.32-504.el6.x86_64 Memory total : 769 MB Memory free : 769 MB Swap total : 815 MB Swap free : 811 MB FileDesc Open : 77 FileDesc Max : 4096 Runtime: Name : 30197@cent62.a5.jp JVM : 25.45-b02 Java HotSpot(TM) 64-Bit Server VM Oracle Corporation Uptime : 2 h, 4 m, 51 s Starttime : Mon May 4 06:59:59 2015