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

沒有留言:

張貼留言