设为首页 收藏本站
查看: 486|回复: 0

[经验分享] cacti 监控tomcat服务

[复制链接]

尚未签到

发表于 2018-12-2 09:48:41 | 显示全部楼层 |阅读模式
  环境: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,添加:
在  下添加
   


5     进入cacti---> console (控制台)---> Data InputMethods(数据输入方法) ---> Tomcat Status
修改Input String(输入流) 中原
      perl/scripts/tomcatstats.pl :8444 admin passwords http-8080
修改为:
      perl /scripts/tomcatstats.pl :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–compilation 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, 保存后就可以看到图了。
  





运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-642257-1-1.html 上篇帖子: tomcat设置独立jvm的例子 下篇帖子: Java技术简介及Tomcat部署
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表