环境:redhat 5.5 windows server 2008
cacti监控tomcat需要安装一些perl的模块,但是搜索发现网上绝大部分都是联网在线安装的,可悲的是公司所维护的生产环境禁止与外网连通,所以原本简单的事又复杂了好多,搞了一天没整出来,最后在一个疲惫的早晨,终于解决了、、、、、
安装Cacti的过程就不废话了。
注意:前提是tomcat服务器要开启tomcat 的manager 管理员账号(必须的)
1 首先下载监控tomcat的模板 TomcatStats-0.1.zip
2 导入模板 (cacti_host_template_tomcat_server.xml)
进入cacti --> Console ---> ImportTemplates
3 将解压缩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::linux
Quit
在没联网的情况下,需要下载模块安装:
Yum install perl* -y
[root@pubservicedb scripts]# ./tomcatstats.pl 10.1.2.24:8080admin passwords http-8080
Can’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�Ccompilation aborted at ./tomcatstats.plline 7.
Perl模块安装方法:
perl Makefile.PL && make&& make install
[root@pubservicedb XML-Simple-2.18]# perl Makefile.PL
Checking installed modules …
You don’t have either XML::SAX or XML::Parser installed!
Checking if your kit is complete…
Looks good
Warning: 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.PL
Cannot determine perl version info fromlib/XML/NamespaceSupport.pm
Checking if your kit is complete…
Looks good
Warning: 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]# make
cp lib/XML/NamespaceSupport.pmblib/lib/XML/NamespaceSupport.pm
Manifying blib/man3/XML::NamespaceSupport.3pm
[root@pubservicedb XML-NamespaceSupport-1.11]# make install
Installing/usr/lib/perl5/site_perl/5.8.8/XML/NamespaceSupport.pm
Installing /usr/share/man/man3/XML::NamespaceSupport.3pm
Writing/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.PL
Checking if your kit is complete…
Looks good
Writing Makefile for XML::SAX::Base
Writing Makefile for XML::SAX
[root@pubservicedb XML-SAX-0.96]# make
cp SAX/PurePerl/Exception.pmblib/lib/XML/SAX/PurePerl/Exception.pm
cp SAX/PurePerl/UnicodeExt.pm blib/lib/XML/SAX/PurePerl/UnicodeExt.pm
… …
cp SAX/PurePerl.pm blib/lib/XML/SAX/PurePerl.pm
cp SAX/Intro.pod blib/lib/XML/SAX/Intro.pod
cp SAX/PurePerl/Reader.pm blib/lib/XML/SAX/PurePerl/Reader.pm
make[1]: Entering directory`/root/monitor/XML-SAX-0.96/XML-SAX-Base’
cp lib/XML/SAX/placeholder.pl../blib/lib/XML/SAX/placeholder.pl
cp lib/XML/SAX/Base.pm ../blib/lib/XML/SAX/Base.pm
cp lib/XML/SAX/Exception.pm ../blib/lib/XML/SAX/Exception.pm
Manifying ../blib/man3/XML::SAX::Base.3pm
Manifying ../blib/man3/XML::SAX::Exception.3pm
make[1]: Leaving directory`/root/monitor/XML-SAX-0.96/XML-SAX-Base’
Manifying blib/man3/XML::SAX::DocumentLocator.3pm
Manifying blib/man3/XML::SAX.3pm
Manifying blib/man3/XML::SAX::PurePerl.3pm
Manifying blib/man3/XML::SAX::Intro.3pm
Manifying blib/man3/XML::SAX::ParserFactory.3pm
Manifying blib/man3/XML::SAX::PurePerl::Reader.3pm
[root@pubservicedb XML-SAX-0.96]# make install
make[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.3pm
Writing/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/XML/SAX/.packlist
Appending installation info to /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/perllocal.pod
could 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.PL
Checking installed modules …
XML::SAX is installed, it will be used by the test suite
Writing Makefile for XML::Simple
[root@pubservicedb XML-Simple-2.18]# make
cp lib/XML/Simple/FAQ.pod blib/lib/XML/Simple/FAQ.pod
cp lib/XML/Simple.pm blib/lib/XML/Simple.pm
Manifying blib/man3/XML::Simple::FAQ.3pm
Manifying blib/man3/XML::Simple.3pm
[root@pubservicedb XML-Simple-2.18]# make install
Installing /usr/lib/perl5/site_perl/5.8.8/XML/Simple.pm
Installing /usr/lib/perl5/site_perl/5.8.8/XML/Simple/FAQ.pod
Installing /usr/share/man/man3/XML::Simple::FAQ.3pm
Installing /usr/share/man/man3/XML::Simple.3pm
Writing/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/XML/Simple/.packlist
Appending 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-8080
jvm_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, 保存后就可以看到图了。