用了整整一天的时间,我终于实现了在 Cacti 下对 Tomcat 的监控,本来挺简单的事,但是具体的实践过程真是费劲周折。废话少说,我先介绍一下一般的配置过程,在介绍的一般配置过程中我们假定 Tomcat 的服务跑在 8080 端口上,在这之后,我会写下我遇到的错误和解决方法,一般配置的步骤如下:
<user username=”admin” password=”passwords” roles=”admin,manager”/>
http://admin:passwords@10.1.2.24:8080/manager/status?XML=true
浏览器会显示相应的 Tomcat 状态信息,如下所示:
Tomcat Status
JVM: free:11466816 total:16318464 max:259522560
Connector — http-8080
threadInfo maxThreads:200 minSpareThreads: maxSpareThreads: currentThreadCount:4 currentThreadsBusy:1
requestInfo maxTime:797 processingTime:5711 requestCount:570 errorCount:51 bytesReceived:0 bytesSent:1228726
Stage Time B Sent B Recv Client VHost Request
S 0 0 0 10.1.2.24 10.1.2.24 GET/manager/status?XML=trueHTTP/1.1
R 0 0 ? ? ?????
R 0 0 ? ? ?????
R 0 0 ? ? ?????
Connector — jk-8009
threadInfo maxThreads:200 minSpareThreads: maxSpareThreads: currentThreadCount:4 currentThreadsBusy:1
requestInfo maxTime:0 processingTime:0 requestCount:0 errorCount:0 bytesReceived:0 bytesSent:0
Stage Time B Sent B Recv Client VHost Request
perl -MCPAN -e”install XML::Simple”
很不幸公司的服务器不允许访问外网,所以我只能手动安装该模块。登录 CPAN 的官方网站搜索并下载安装包,安装前请仔细查看 README 文件,该文件会介绍的安装包的依赖包,如果机器上没有还需要先安装上依赖包。实践中具体的安装和测试脚本过程如下:
[root@pubservicedb scripts]# ./tomcatstats.pl 10.1.2.24:8080 admin 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–compilation aborted at ./tomcatstats.pl line 7.
[root@pubservicedb scripts]#[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 from lib/XML/NamespaceSupport.pm
Checking if your kit is complete…
Looks good
Warning: prerequisite ExtUtils::MakeMaker 6.42 not found. We have 6.30.
Writing Makefile for XML::NamespaceSupport
[root@pubservicedb XML-NamespaceSupport-1.11]# make
cp lib/XML/NamespaceSupport.pm blib/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/.packlist
Appending installation info to /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/perllocal.pod
[root@pubservicedb XML-NamespaceSupport-1.11]#[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.pm blib/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]#[root@pubservicedb scripts]# ./tomcatstats.pl 10.1.2.24:8080 admin passwords http-8080
jvm_memory_free:11742544 jvm_memory_max:259522560 jvm_memory_total:16318464 connector_max_time:797 connector_error_count:5 connector_bytes_sent:49396 connector_processing_time:1405 connector_request_count:12 connector_bytes_received:0 connector_current_thread_count:2 connector_min_spare_threads: connector_max_threads:200 connector_max_spare_threads: connector_current_threads_busy:1 [root@pubservicedb scripts]#
perl /scripts/tomcatstats.pl <hostname>:8080 admin passwords http-8080
下面我来说说配置中遇到的错误和问题:
05/20/2011 11:05:07 AM – POLLER: Poller[0] CACTI2RRD: /usr/local/bin/rrdtool update /usr/local/apache/htdocs/cacti/rra/10_1_2_24_current_threads_bus_747.rrd –template 1305860706:0
ERROR: Not enough arguments
这个问题很诡异,我提高了 Poller 的日志等级才发现,而且我在 Poller 的设置中如果选择 cmd.php 的方式轮询则系统会取到数据,这就基本确定了这个问题出在了 Spine 上。自己上网找了很长时间,终于在 Cacti 的 官方论坛 中找到答案。安装论坛中的解决方法给 Cacti 和 Spine 分别打了补丁,并重新编译了 Spine 组件,问题迎刃而解啦。
考虑到 Tomcat 的应用的安全性和不同 Tomcat 的应用配置路径不同的问题,我推荐大家使用 INSTALL 文件中介绍配置 Tomcat 方式,修改 server.xml 配置文件,并添加以下内容:
<Service name=”Admin”>
<Connector port=”8444″ maxHttpHeaderSize=”8192″ maxThreads=”150″ minSpareThreads=”25″ maxSpareThreads=”75″ enableLookups=”false” disableUploadTimeout=”true” acceptCount=”100″ scheme=”https” secure=”true” clientAuth=”false” sslProtocol=”TLS” />
<Engine name=”Admin” defaultHost=”localhost”>
<Realm className=”org.apache.catalina.realm.UserDatabaseRealm” resourceName=”UserDatabase”/>
<Host name=”localhost” appBase=”server/webapps” unpackWARs=”false” autoDeploy=”false” xmlValidation=”false” xmlNamespaceAware=”false”>
<Valve className=”org.apache.catalina.valves.FastCommonAccessLogValve” directory=”logs” prefix=”admin_access_log.” suffix=”.txt” pattern=”combined” resolveHosts=”false” fileDateFormat=”yyy-MM-dd”/>
<Context path=”/manager” cookies=”false” docBase=”server/webapps/manager” debug=”0″ privileged=”true” reloadable=”false” />
</Host>
</Engine>
</Service>
该服务跑在了 8444 端口,请在 Cacti 界面的 “Data Input Methods” 中修改相应的路径和端口号。
想完全理解 Cacti 真的很难,很高兴我又前进了一小步,这次的配置过程让我更加深入的了解了 Cacti 的模板机制,以及底层的 RRDTool 的工作原理和服务器上 Poller.php 的 cron 轮询机制,最重要的通过查询 Cacti 的 使用手册,我的 Debugging 技巧又提高不少,希望在不久的将来我能自己写出牛逼的监控脚本和模板,也为 Cacti 社区做出自己的一点点贡献!
联系客服