之前在測試 JVM SNMP + JMX 時,皆是以 Tomcat 做為 LAB 的測試標的.
但在使用 /usr/local/tomcat/shutdown.sh 將 tomcat 的服務停止時,
總會產生 tomcat Error: Failed to start SNMP adaptor with address 這樣的訊息.
最後總是直接使用 killall -9 去停止該項服務.最後 google 到 解法.
資料參考 http://www.tikalk.com/java/forums/when-use-tomcat-catalina-opts-instead-java-opts
將 JMX & SNMP 的 JAVA_OPTS 從 /etc/profile.d/java.sh
移到 /usr/local/tomcat/startup.sh
在上方處放上原先設定:
export JAVA_OPTS="-Dcom.sun.management.snmp.port=1610 -Dcom.sun.management.snmp.acl.file=/usr/java/jre/lib/management/snmp.acl -Dcom.sun.management.snmp.interface=0.0.0.0 -Xms1024m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=256m -Dcom.sun.management.jmxremote -Djava.rmi.server.hostname=192.168.100.101 -Dcom.sun.management.jmxremote.port=9012 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"
相關文章如下:
Cacti JVM Monitoring template ( Part I )
http://xrcd2.blogspot.tw/2012/12/cacti-jvm-monitoring-template.html
Cacti JVM Monitoring template ( Part II )
http://xrcd2.blogspot.tw/2013/01/cacti-jvm-monitoring-template-part-ii.html
jmx4perl ( JMX access for Perl )
http://xrcd2.blogspot.tw/2013/01/jmx4perl-jmx-access-for-perl.html
JVM Monitor tools
http://visualvm.java.net/
2013年1月5日 星期六
2013年1月3日 星期四
jmx4perl ( JMX access for Perl )
延續 Cacti JVM Monitoring 這個主題.
JMX 是一個標準.可使用 ant 或 jconsole 去取得 JVM 的效能相關數據資料,
以下再介紹使用 webapps agent + perl 的用法,同樣的以 tomcat 為 LAB!
tomcat-connectors
http://tomcat.apache.org/connectors-doc/
#wget http://www.apache.org/dist/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.37-src.tar.gz
#tar -zvxf tomcat-connectors-1.2.37-src.tar.gz
#cd tomcat-connectors-1.2.37-src/native
#./buildconf.sh
#./configure --with-apxs=/usr/sbin/apxs
#make
#make install
#vi /etc/httpd/conf/httpd.conf
LoadModule jk_module modules/mod_jk.so
#service httpd restart
jolokia (Jolokia is remote JMX with JSON over HTTP)
http://www.jolokia.org/
Jolokia Quickstart
http://www.jolokia.org/tutorial.html
#wget http://www.jolokia.org/dist/1.0.6/jolokia-1.0.6-bin.tar.gz
#tar -zvxf olokia-1.0.6-bin.tar.gz
#cp ./jolokia-1.0.6/agents/jolokia.war /usr/local/tomcat/webapps
#cp ./jolokia-1.0.6/agents/*.jar /usr/local/tomcat/lib
#/usr/local/tomcat/shutdown.sh
#/usr/local/tomcat/startup.sh
test jolokia url
http://jmx.tomcat.server.ip:8080/jolokia/
Perl
install JMX::Jmx4Perl JMX::Jmx4Perl::Alia
#cpan install JMX::Jmx4Perl JMX::Jmx4Perl::Alias
About Jmx4Perl.pm Alias.pm
JMX access for Perl (jmx4perl)
http://search.cpan.org/~roland/jmx4perl/lib/JMX/Jmx4Perl.pm
JMX alias names for jmx4perl
http://search.cpan.org/~roland/jmx4perl-0.71/lib/JMX/Jmx4Perl/Alias.pm
[root@centos63 tmp]# cat jmx.pl
#!/usr/bin/perl
use JMX::Jmx4Perl;
use JMX::Jmx4Perl::Alias;
$jmx1 = JMX::Jmx4Perl->new(url => "http://localhost:8080/jolokia")->get_attribute(MEMORY_HEAP_USED);
$jmx2 = JMX::Jmx4Perl->new(url => "http://localhost:8080/jolokia")->get_attribute(THREAD_COUNT);
print "\n JMX MEMORY_HEAP_USED= $jmx1 \n\n";
print "\n ThreadCount= $jmx2 \n\n";
[root@centos63 tmp]# perl jmx.pl
JMX MEMORY_HEAP_USED= 31746000
ThreadCount= 22
對照 jmx4perl 與 cacti 看到的資料是否一致!
相關文章如下:
Cacti JVM Monitoring template ( Part I )
http://xrcd2.blogspot.tw/2012/12/cacti-jvm-monitoring-template.html
Cacti JVM Monitoring template ( Part II )
http://xrcd2.blogspot.tw/2013/01/cacti-jvm-monitoring-template-part-ii.html
JMX 是一個標準.可使用 ant 或 jconsole 去取得 JVM 的效能相關數據資料,
以下再介紹使用 webapps agent + perl 的用法,同樣的以 tomcat 為 LAB!
tomcat-connectors
http://tomcat.apache.org/connectors-doc/
#wget http://www.apache.org/dist/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.37-src.tar.gz
#tar -zvxf tomcat-connectors-1.2.37-src.tar.gz
#cd tomcat-connectors-1.2.37-src/native
#./buildconf.sh
#./configure --with-apxs=/usr/sbin/apxs
#make
#make install
#vi /etc/httpd/conf/httpd.conf
LoadModule jk_module modules/mod_jk.so
#service httpd restart
jolokia (Jolokia is remote JMX with JSON over HTTP)
http://www.jolokia.org/
Jolokia Quickstart
http://www.jolokia.org/tutorial.html
#wget http://www.jolokia.org/dist/1.0.6/jolokia-1.0.6-bin.tar.gz
#tar -zvxf olokia-1.0.6-bin.tar.gz
#cp ./jolokia-1.0.6/agents/jolokia.war /usr/local/tomcat/webapps
#cp ./jolokia-1.0.6/agents/*.jar /usr/local/tomcat/lib
#/usr/local/tomcat/shutdown.sh
#/usr/local/tomcat/startup.sh
test jolokia url
http://jmx.tomcat.server.ip:8080/jolokia/
Perl
install JMX::Jmx4Perl JMX::Jmx4Perl::Alia
#cpan install JMX::Jmx4Perl JMX::Jmx4Perl::Alias
About Jmx4Perl.pm Alias.pm
JMX access for Perl (jmx4perl)
http://search.cpan.org/~roland/jmx4perl/lib/JMX/Jmx4Perl.pm
JMX alias names for jmx4perl
http://search.cpan.org/~roland/jmx4perl-0.71/lib/JMX/Jmx4Perl/Alias.pm
[root@centos63 tmp]# cat jmx.pl
#!/usr/bin/perl
use JMX::Jmx4Perl;
use JMX::Jmx4Perl::Alias;
$jmx1 = JMX::Jmx4Perl->new(url => "http://localhost:8080/jolokia")->get_attribute(MEMORY_HEAP_USED);
$jmx2 = JMX::Jmx4Perl->new(url => "http://localhost:8080/jolokia")->get_attribute(THREAD_COUNT);
print "\n JMX MEMORY_HEAP_USED= $jmx1 \n\n";
print "\n ThreadCount= $jmx2 \n\n";
[root@centos63 tmp]# perl jmx.pl
JMX MEMORY_HEAP_USED= 31746000
ThreadCount= 22
對照 jmx4perl 與 cacti 看到的資料是否一致!
相關文章如下:
Cacti JVM Monitoring template ( Part I )
http://xrcd2.blogspot.tw/2012/12/cacti-jvm-monitoring-template.html
Cacti JVM Monitoring template ( Part II )
http://xrcd2.blogspot.tw/2013/01/cacti-jvm-monitoring-template-part-ii.html
Cacti JVM Monitoring template ( Part II )
延續 Cacti JVM Monitoring template 這個主題,
上次已提過 JVM Monitor 的二種型態!
分別為: (1) java snmp (2) jmx
其中的 java snmp 的使用方式請參考 Cacti JVM Monitoring template ( Part I ) URL 如下:
http://xrcd2.blogspot.tw/2012/12/cacti-jvm-monitoring-template.html
接下來要介紹的是,透過 jmx 的方式與 cacti 的運用.
本 LAB 的假設情境為 使用 tomcat 做為 jmx 的 監控目標.
利用 Percona JMX Monitoring Template for Cacti 的方式,進行 jmx monitor
安裝與測試方式參考如下:
http://www.percona.com/doc/percona-monitoring-plugins/cacti/jmx-templates.html
其中的重點是要設定 ant 及 jmx 的使用環境.
請自行參考 Cacti JVM Monitoring template 的 /etc/profile.d/java.sh 的設定.
ant 可於 http://ant.apache.org/ download
#wget http://apache.cdpa.nsysu.edu.tw//ant/binaries/apache-ant-1.8.4-bin.tar.gz
#tar -zvxf apache-ant-1.8.4-bin.tar.gz
#mv apache-ant-1.8.4 /usr/local/ant (配合 /etc/profile.d/java.sh 的設定 )
可透過 ant -version 去測試 ant 是否可以正常使用.
[root@centos bin]# pwd
/usr/local/ant/bin
[root@centos bin]# ./ant -version
Apache Ant(TM) version 1.8.4 compiled on May 22 2012
接下來是 cp /usr/local/tomcat/lib/catalina.jar /home/cactiuser/.ant/lib
download percona-monitoring-plugins-1.0.1.tar.gz 下來使用,URL 如下:
http://www.percona.com/downloads/percona-monitoring-plugins/
解開 percona-monitoring-plugins-1.0.1.tar.gz
在 cacti web 中 使用 Import Templates 將
templates/cacti_host_template_percona_jmx_server_ht_0.8.6i-sver1.0.1.xml 匯入
cp misc/jmx-monitor.xml /home/cacti 供 ss_get_by_ssh.php 使用
cp scripts/ss_get_by_ssh.php /var/www/html/cacti/scripts/ 供 cacti Data Input Methods 使用
而 ss_get_by_ssh.php 則是必須建立 ssh key 方可使用
可參考 [實用的 Cacti Monitoring Template] 一文中的介紹
http://xrcd2.blogspot.tw/2012/05/cacti-monitoring-template.html
上述的檔案中,必須修改的是 ss_get_by_ssh.php & jmx-monitor.xml
請參考下圖:
設定 jmx 不使用 id & pwd 方式即可連入 jmx server
設定 ssh key 的 使用 id & key file
在全數前置作業完成後可透過指令 ant -Djmx.server.port=9012 -e -q -f jmx-monitor.xml
去驗證設定是否正確及運作正常
[root@centos cactiuser]# su - cactiuser
[cactiuser@centos ~]$ ant -Djmx.server.port=9012 -e -q -f jmx-monitor.xml
BUILD FAILED
/home/cactiuser/jmx-monitor.xml:53: javax.management.InstanceNotFoundException: Catalina:type=ThreadPool,name=${jmx.catalina.threadpool.name}
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getMBean(DefaultMBeanServerInterceptor.java:1094)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getAttribute(DefaultMBeanServerInterceptor.java:662)
at com.sun.jmx.mbeanserver.JmxMBeanServer.getAttribute(JmxMBeanServer.java:638)
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1431)
at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:74)
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1295)
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1387)
at javax.management.remote.rmi.RMIConnectionImpl.getAttribute(RMIConnectionImpl.java:630)
at sun.reflect.GeneratedMethodAccessor50.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:303)
at sun.rmi.transport.Transport$1.run(Transport.java:159)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:142)
at com.sun.jmx.remote.internal.PRef.invoke(Unknown Source)
at javax.management.remote.rmi.RMIConnectionImpl_Stub.getAttribute(Unknown Source)
at javax.management.remote.rmi.RMIConnector$RemoteMBeanServerConnection.getAttribute(RMIConnector.java:878)
at org.apache.catalina.ant.jmx.JMXAccessorGetTask.jmxGet(JMXAccessorGetTask.java:136)
at org.apache.catalina.ant.jmx.JMXAccessorGetTask.jmxExecute(JMXAccessorGetTask.java:121)
at org.apache.catalina.ant.jmx.JMXAccessorTask.execute(JMXAccessorTask.java:347)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl. java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:392)
at org.apache.tools.ant.Target.performTasks(Target.java:413)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExe cutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.Main.runBuild(Main.java:811)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Total time: 1 second
及
[cactiuser@centos ~]$php /var/www/html/cacti/scripts/ss_get_by_ssh.php --type jmx --host 127.0.0.1 --items j4,j5,j6,j7,j8,j9,ja,jb
j4:131728176 j5:1037959168 j6:1037959168 j7:25814184 j8:159055872 j9:325058560 ja:52 jb:4096
分別去驗證 jmx-monitor.xml & ss_get_by_ssh.php 的設定
接下來就是在 cacti web 中將 Host Templates \ Percona JMX Server HT 直接拿來使用
實作畫面如下:
上次已提過 JVM Monitor 的二種型態!
分別為: (1) java snmp (2) jmx
其中的 java snmp 的使用方式請參考 Cacti JVM Monitoring template ( Part I ) URL 如下:
http://xrcd2.blogspot.tw/2012/12/cacti-jvm-monitoring-template.html
接下來要介紹的是,透過 jmx 的方式與 cacti 的運用.
本 LAB 的假設情境為 使用 tomcat 做為 jmx 的 監控目標.
利用 Percona JMX Monitoring Template for Cacti 的方式,進行 jmx monitor
安裝與測試方式參考如下:
http://www.percona.com/doc/percona-monitoring-plugins/cacti/jmx-templates.html
其中的重點是要設定 ant 及 jmx 的使用環境.
請自行參考 Cacti JVM Monitoring template 的 /etc/profile.d/java.sh 的設定.
ant 可於 http://ant.apache.org/ download
#wget http://apache.cdpa.nsysu.edu.tw//ant/binaries/apache-ant-1.8.4-bin.tar.gz
#tar -zvxf apache-ant-1.8.4-bin.tar.gz
#mv apache-ant-1.8.4 /usr/local/ant (配合 /etc/profile.d/java.sh 的設定 )
可透過 ant -version 去測試 ant 是否可以正常使用.
[root@centos bin]# pwd
/usr/local/ant/bin
[root@centos bin]# ./ant -version
Apache Ant(TM) version 1.8.4 compiled on May 22 2012
接下來是 cp /usr/local/tomcat/lib/catalina.jar /home/cactiuser/.ant/lib
download percona-monitoring-plugins-1.0.1.tar.gz 下來使用,URL 如下:
http://www.percona.com/downloads/percona-monitoring-plugins/
解開 percona-monitoring-plugins-1.0.1.tar.gz
在 cacti web 中 使用 Import Templates 將
templates/cacti_host_template_percona_jmx_server_ht_0.8.6i-sver1.0.1.xml 匯入
cp misc/jmx-monitor.xml /home/cacti 供 ss_get_by_ssh.php 使用
cp scripts/ss_get_by_ssh.php /var/www/html/cacti/scripts/ 供 cacti Data Input Methods 使用
而 ss_get_by_ssh.php 則是必須建立 ssh key 方可使用
可參考 [實用的 Cacti Monitoring Template] 一文中的介紹
http://xrcd2.blogspot.tw/2012/05/cacti-monitoring-template.html
上述的檔案中,必須修改的是 ss_get_by_ssh.php & jmx-monitor.xml
請參考下圖:
設定 jmx 不使用 id & pwd 方式即可連入 jmx server
設定 ssh key 的 使用 id & key file
在全數前置作業完成後可透過指令 ant -Djmx.server.port=9012 -e -q -f jmx-monitor.xml
去驗證設定是否正確及運作正常
[root@centos cactiuser]# su - cactiuser
[cactiuser@centos ~]$ ant -Djmx.server.port=9012 -e -q -f jmx-monitor.xml
BUILD FAILED
/home/cactiuser/jmx-monitor.xml:53: javax.management.InstanceNotFoundException: Catalina:type=ThreadPool,name=${jmx.catalina.threadpool.name}
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getMBean(DefaultMBeanServerInterceptor.java:1094)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getAttribute(DefaultMBeanServerInterceptor.java:662)
at com.sun.jmx.mbeanserver.JmxMBeanServer.getAttribute(JmxMBeanServer.java:638)
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1431)
at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:74)
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1295)
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1387)
at javax.management.remote.rmi.RMIConnectionImpl.getAttribute(RMIConnectionImpl.java:630)
at sun.reflect.GeneratedMethodAccessor50.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:303)
at sun.rmi.transport.Transport$1.run(Transport.java:159)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:142)
at com.sun.jmx.remote.internal.PRef.invoke(Unknown Source)
at javax.management.remote.rmi.RMIConnectionImpl_Stub.getAttribute(Unknown Source)
at javax.management.remote.rmi.RMIConnector$RemoteMBeanServerConnection.getAttribute(RMIConnector.java:878)
at org.apache.catalina.ant.jmx.JMXAccessorGetTask.jmxGet(JMXAccessorGetTask.java:136)
at org.apache.catalina.ant.jmx.JMXAccessorGetTask.jmxExecute(JMXAccessorGetTask.java:121)
at org.apache.catalina.ant.jmx.JMXAccessorTask.execute(JMXAccessorTask.java:347)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl. java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:392)
at org.apache.tools.ant.Target.performTasks(Target.java:413)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExe cutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.Main.runBuild(Main.java:811)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Total time: 1 second
及
[cactiuser@centos ~]$php /var/www/html/cacti/scripts/ss_get_by_ssh.php --type jmx --host 127.0.0.1 --items j4,j5,j6,j7,j8,j9,ja,jb
j4:131728176 j5:1037959168 j6:1037959168 j7:25814184 j8:159055872 j9:325058560 ja:52 jb:4096
分別去驗證 jmx-monitor.xml & ss_get_by_ssh.php 的設定
接下來就是在 cacti web 中將 Host Templates \ Percona JMX Server HT 直接拿來使用
實作畫面如下:
訂閱:
文章 (Atom)