延續 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 直接拿來使用
實作畫面如下:
沒有留言:
張貼留言