您的位置:首页 > 运维架构 > Tomcat

cacti 监控tomcat服务

2014-04-14 22:37 405 查看
环境:redhat 5.5 windows server 2008

cacti监控tomcat需要安装一些perl的模块,但是搜索发现网上绝大部分都是联网在线安装的,可悲的是公司所维护的生产环境禁止与外网连通,所以原本简单的事又复杂了好多,搞了一天没整出来,最后在一个疲惫的早晨,终于解决了、、、、、

安装Cacti的过程就不废话了。注意:前提是tomcat服务器要开启tomcat 的manager 管理员账号(必须的)1 首先下载监控tomcat的模板 TomcatStats-0.1.zip2 导入模板 (cacti_host_template_tomcat_server.xml)进入cacti --> Console ---> ImportTemplates3 将解压缩TomcatStats-0.1.zip得到的tomcatstats.pl 放到cacti/scritps目录下。修改tomcatstats.pl,将my $xml = `GET $url`;修改为my $xml = `wget -qO - $url`;此处的-qO中的O为大写字母欧O;不然在你导入之后很可能出现数据出不来4 然后修改被监控tomcat的配置文件,$tomcat/conf/tomcat-users.xml,添加:在 <tomcat-users> 下添加 <user username="admin"password="password" roles="admin,manager"/>
5 进入cacti---> console (控制台)---> Data InputMethods(数据输入方法) ---> Tomcat Status修改Input String(输入流) 中原 perl<path_cacti>/scripts/tomcatstats.pl <hostname>:8444 admin passwords http-8080修改为: perl <path_cacti>/scripts/tomcatstats.pl <hostname>:8080 admin password http-8080

6 Cacti中增加相关监控选项。要点:(cacti服务端)1 需要安装 XML::Simple (此时需要联网) Yum install perl*-y (此步骤可不做)安装方法: (perl -MCPAN -e"installXML::Simple")Cpan o confcommit InstallSys::Statistics::linuxQuit
在没联网的情况下,需要下载模块安装:Yum install perl* -y[root@pubservicedb scripts]# ./tomcatstats.pl 10.1.2.24:8080admin passwords http-8080Can’t locate XML/Simple.pm in @INC (@INC contains:/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl/usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi/usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/5.8.8 .) at./tomcatstats.pl line 7.BEGIN failed–compilation aborted at ./tomcatstats.plline 7.Perl模块安装方法:perl Makefile.PL && make&& make install[root@pubservicedb XML-Simple-2.18]# perl Makefile.PLChecking installed modules …You don’t have either XML::SAX or XML::Parser installed!Checking if your kit is complete…Looks goodWarning: prerequisite XML::NamespaceSupport 1.04 not found.Warning: prerequisite XML::SAX 0 not found.Warning: prerequisite XML::SAX::Expat 0 not found.Writing Makefile for XML::Simple[root@pubservicedb XML-Simple-2.18]#[root@pubservicedb XML-NamespaceSupport-1.11]# perl Makefile.PLCannot determine perl version info fromlib/XML/NamespaceSupport.pmChecking if your kit is complete…Looks goodWarning: prerequisite ExtUtils::MakeMaker 6.42 not found. Wehave 6.30.Writing Makefile for XML::NamespaceSupport出错了:需要安装ExtUtils-MakeMaker-6.94.tar.gz Task-Weaken-1.04.tar.gz然后在安装[root@pubservicedb XML-NamespaceSupport-1.11]# makecp lib/XML/NamespaceSupport.pmblib/lib/XML/NamespaceSupport.pmManifying blib/man3/XML::NamespaceSupport.3pm[root@pubservicedb XML-NamespaceSupport-1.11]# make installInstalling/usr/lib/perl5/site_perl/5.8.8/XML/NamespaceSupport.pmInstalling /usr/share/man/man3/XML::NamespaceSupport.3pmWriting/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/XML/NamespaceSupport/.packlistAppendinginstallation info to /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/perllocal.pod [root@pubservicedb XML-NamespaceSupport-1.11]# cd ..[root@pubservicedb monitor]# cd XML-SAX-0.96[root@pubservicedb XML-SAX-0.96]# perl Makefile.PLChecking if your kit is complete…Looks goodWriting Makefile for XML::SAX::BaseWriting Makefile for XML::SAX[root@pubservicedb XML-SAX-0.96]# makecp SAX/PurePerl/Exception.pmblib/lib/XML/SAX/PurePerl/Exception.pmcp SAX/PurePerl/UnicodeExt.pm blib/lib/XML/SAX/PurePerl/UnicodeExt.pm… …cp SAX/PurePerl.pm blib/lib/XML/SAX/PurePerl.pmcp SAX/Intro.pod blib/lib/XML/SAX/Intro.podcp SAX/PurePerl/Reader.pm blib/lib/XML/SAX/PurePerl/Reader.pmmake[1]: Entering directory`/root/monitor/XML-SAX-0.96/XML-SAX-Base’cp lib/XML/SAX/placeholder.pl../blib/lib/XML/SAX/placeholder.plcp lib/XML/SAX/Base.pm ../blib/lib/XML/SAX/Base.pmcp lib/XML/SAX/Exception.pm ../blib/lib/XML/SAX/Exception.pmManifying ../blib/man3/XML::SAX::Base.3pmManifying ../blib/man3/XML::SAX::Exception.3pmmake[1]: Leaving directory`/root/monitor/XML-SAX-0.96/XML-SAX-Base’Manifying blib/man3/XML::SAX::DocumentLocator.3pmManifying blib/man3/XML::SAX.3pmManifying blib/man3/XML::SAX::PurePerl.3pmManifying blib/man3/XML::SAX::Intro.3pmManifying blib/man3/XML::SAX::ParserFactory.3pmManifying blib/man3/XML::SAX::PurePerl::Reader.3pm[root@pubservicedb XML-SAX-0.96]# make installmake[1]: Entering directory`/root/monitor/XML-SAX-0.96/XML-SAX-Base’make[1]: Leaving directory `/root/monitor/XML-SAX-0.96/XML-SAX-Base’Installing /usr/lib/perl5/site_perl/5.8.8/XML/SAX.pm… …Installing /usr/share/man/man3/XML::SAX::PurePerl.3pmWriting/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/XML/SAX/.packlistAppending installation info to /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/perllocal.podcould not find ParserDetails.ini in/usr/lib/perl5/site_perl/5.8.8/XML/SAX[root@pubservicedb XML-SAX-0.96]#[root@pubservicedb monitor]# cd XML-Simple-2.18[root@pubservicedb XML-Simple-2.18]# perl Makefile.PLChecking installed modules …XML::SAX is installed, it will be used by the test suiteWriting Makefile for XML::Simple[root@pubservicedb XML-Simple-2.18]# makecp lib/XML/Simple/FAQ.pod blib/lib/XML/Simple/FAQ.podcp lib/XML/Simple.pm blib/lib/XML/Simple.pmManifying blib/man3/XML::Simple::FAQ.3pmManifying blib/man3/XML::Simple.3pm[root@pubservicedb XML-Simple-2.18]# make installInstalling /usr/lib/perl5/site_perl/5.8.8/XML/Simple.pmInstalling /usr/lib/perl5/site_perl/5.8.8/XML/Simple/FAQ.podInstalling /usr/share/man/man3/XML::Simple::FAQ.3pmInstalling /usr/share/man/man3/XML::Simple.3pmWriting/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/XML/Simple/.packlistAppending installation info to/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/perllocal.pod[root@pubservicedb XML-Simple-2.18]# 有可能还需要安装 XML-Parser-2.41.tar.gz[root@pubservicedb scripts]# ./tomcatstats.pl 10.1.2.24:8080 admin password http-8080jvm_memory_free:11742544 jvm_memory_max:259522560jvm_memory_total:16318464 connector_max_time:797 connector_error_count:5connector_bytes_sent:49396 connector_processing_time:1405connector_request_count:12 connector_bytes_received:0connector_current_thread_count:2 connector_min_spare_threads:connector_max_threads:200 connector_max_spare_threads:connector_current_threads_busy:1 [root@pubservicedb scripts]#

2 Tomcat manager的设置,设置完成后可以用INSTALL中提到的方法来测试./tomcatstats.pltomcatip:8080 admin password http-8080(1)、如果提示:-bash: ./tomcatstats.pl: /usr/bin/perl^M: bad interpreter: No suchfile编辑tomcatstats.pl,将首行改为:#!/usr/bin/perl -w (加上-w),但有时候加上“-w ”又会有新的问题出现,所以最好的方法还是:sed -i ‘s/\r$//’ tomcatstats.pl
(2)、如果提示:File does not exist: at ./tomcatstats.pl line 21(21行是:my $status = XMLin($xml);)说明无法得到远程tomcat服务器数据,检查tomcat配置的用户是否生效。
出问题时:/usr/bin/perl^M: badinterpreter 没有那个文件或目录解决办法:Windows下,每一行的结尾是\n\r,而在linux下文件的结尾是\n。用cat -A filename时你可以看到这个\r字符被显示为^M。

解决方法: sed -i ‘s/\r$//’ tomcatstats.pl

结果:
jvm_memory_free:64522688 jvm_memory_max:1023934464jvm_memory_total:81854464 connector_max_time:66 connector_error_count:19connector_bytes_sent:2957318 connector_processing_time:804connector_request_count:677 connector_bytes_received:0connector_current_thread_count:25 connector_min_spare_threads:25connector_max_threads:150 connector_max_spare_threads:75connector_current_threads_busy:2 3 如果图前面设置都正确,图没有出来,可以尝试把 Templates -->GraphTemplates--Unit Grid Value 中清空.
注:上面做完后你们可能会发现有2张图出不来,分别是heap statistics 和connnect rate, 请按下面的方法来做。 console--->graph templates--->找到相对应的模板(点进去找到)---Unit Grid Value (--unit/--y-grid) 设置为0, 保存后就可以看到图了。

本文出自 “残月” 博客,请务必保留此出处http://waning411.blog.51cto.com/4909368/1395602
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: