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

[经验分享] Cacti监控Tomcat服务器实现过程

[复制链接]
发表于 2015-11-22 14:01:57 | 显示全部楼层 |阅读模式
  1 首先去官网上面下载通用的监控模板
  一般使用TomcatStats-0.1.zip 模板居多,下载地址:
  http://forums.cacti.net/download/file.php?id=12310,
  在linux服务器上面使用wget下载,wget http://forums.cacti.net/download/file.php?id=12310,报如下错误:
  正在连接 forums.cacti.net|173.225.179.10|:80... 已连接。
  已发出 HTTP 请求,正在等待回应... 301 Moved Permanently
  位置:http://forums.cacti.net/ [跟随至新的 URL]
  已超过 20 次重定向。
  
  可以在windows7的google浏览器上输入http://forums.cacti.net/download/file.php?id=12310点击回车下载,然后通过SecureFX客户端工具scp到linux服务器上即可。
  然后解压缩得到3个文件cacti_host_template_tomcat_server.xml,INSTALL.txt,tomcatstats.pl 3个文件。
  
  2 在cacti主服务器的网址上面导入模板
  打开cacti服务器的网址:
  进入http://10.xx.1.xx/cacti/index.php->Console –> Templates -> Import Templates ,选择文件导入(cacti_host_template_tomcat_server.xml)文件,选择Import按钮加载tomcat模板。
DSC0000.jpg

  3 cacti服务器端加载tomcatstats.pl统计脚本
  
  将解压缩TomcatStats-0.1.zip 得到的tomcatstats.pl 放到/var/www/html/cacti/scritps 目录下,并且赋予执行权限
  Chown –R apache.apache tomcatstats.pl
  chmod 755 tomcatstats.pl
  修改tomcatstats.pl,大概第20行,将
  1.      my $xml = `GET $url`;
  修改为
  1.      my $xml = `wget -qO - $url`;
  不然在你导入之后很可能出现数据出不来。
  Check URL连接是否正确
  Vim tomcatstats.pl 后,在第17行后面添加print $url,在控制台打出url,如下所示:   
  my $url = "http://$username:$password"."\@$host/manager/status?XML=true";
  print $url;
  print “   ”;
  
  然后用perl来check下统计脚本,如下:
  [iyunv@squid-2 scripts]# perl tomcatstats.pl 10.xx.3.xx:9444 'tomcat' '9ssspw '  http-9444  
  http://tomcat:tomcat0401@10.xx.3.xx:9444/manager/status?XML=true   jvm_memory_free:2925944104 jvm_memory_max:3892314112 jvm_memory_total:3892314112 connector_max_time:131 connector_error_count:4464 connector_bytes_sent:19559190 connector_processing_time:11552 connector_request_count:8931 connector_bytes_received:0 connector_current_thread_count:4 connector_min_spare_threads: connector_max_threads:150 connector_max_spare_threads: connector_current_threads_busy:1

  也可以在windows7的google浏览器里面,输入上面URL,也会出现很多tomcat的统计信息,如下所示:
DSC0001.jpg

  
  4 修改cacti中tomcat获取数据的url地址
  进入cacti---> console ---> Data Input Methods --->Tomcat Status
  修改Input String 中字段
  修改为:perl <path_cacti>/scripts/tomcatstats.pl <hostname>:8080 tomcat 9ssspw  http-8080
  注意:替换上面的username 和password 为实际的tomcat 管理员账号和密码。
  要开启tomcat 的manager 管理员账号 附件内有Enable the Tomcat manager application 介绍,如下图:
DSC0002.jpg

  
  5 web端tomcat服务器的配置调整
  在tomcat/conf/server.xml 里面添加如下:
  <Service name=&quot;Admin&quot;>
  <Connector port=&quot;9444&quot; maxHttpHeaderSize=&quot;8192&quot;
  maxThreads=&quot;150&quot; minSpareThreads=&quot;25&quot; maxSpareThreads=&quot;75&quot;
  enableLookups=&quot;false&quot; disableUploadTimeout=&quot;true&quot;
  acceptCount=&quot;100&quot; scheme=&quot;https&quot; secure=&quot;true&quot;
  clientAuth=&quot;false&quot; sslProtocol=&quot;TLS&quot; />
  <Engine name=&quot;Admin&quot; defaultHost=&quot;localhost&quot;>
  <Realm className=&quot;org.apache.catalina.realm.UserDatabaseRealm&quot;
  resourceName=&quot;UserDatabase&quot;/>
  <Host name=&quot;localhost&quot; appBase=&quot;webapps&quot;
  unpackWARs=&quot;false&quot; autoDeploy=&quot;false&quot;
  xmlValidation=&quot;false&quot; xmlNamespaceAware=&quot;false&quot;>
  <Valve className=&quot;org.apache.catalina.valves.FastCommonAccessLogValve&quot;
  directory=&quot;logs&quot;  prefix=&quot;admin_access_log.&quot; suffix=&quot;.txt&quot;
  pattern=&quot;combined&quot; resolveHosts=&quot;false&quot;
  fileDateFormat=&quot;yyy-MM-dd&quot;/>
  <Context path=&quot;/manager&quot; cookies=&quot;false&quot;
  docBase=&quot;server/webapps/manager&quot; debug=&quot;0&quot;
  privileged=&quot;true&quot; reloadable=&quot;false&quot; />
  </Host>
  </Engine>
  </Service>
  然后在tomcat/conf/tomcat-users.xml里面 添加
  <role rolename=&quot;manager-gui&quot;/>
  <user username=&quot;tomcat&quot; password=&quot;9ssspw &quot; roles=&quot;manager-gui&quot;/>
  passwords 为连接密码 可自行更改,然后重启tomcat 服务
  
  去cacti服务器端执行perl tomcatstats.pl 10.xx.3.xx:9444 'tomcat' '9ssspw '  http-9444 check统计脚本是否能取到tomcat的数据,有数据即正常,如下所示:
  [iyunv@squid-2 scripts]# /usr/bin/perl tomcatstats.pl 10.xx.3.xx:9444 'tomcat' 'xxx’  http-9444
  http://tomcat:tomcat0401@10.254.3.29:9444/manager/status?XML=true   jvm_memory_free:3409129096 jvm_memory_max:3892314112 jvm_memory_total:3892314112 connector_max_time:131 connector_error_count:2 connector_bytes_sent:20241 connector_processing_time:168 connector_request_count:5 connector_bytes_received:0 connector_current_thread_count:4 connector_min_spare_threads: connector_max_threads:150 connector_max_spare_threads: connector_current_threads_busy:1
  [iyunv@squid-2 scripts]#
  
  记录debug期间的报错信息如下:
  [iyunv@squid-2 scripts]# perl tomcatstats.pl 10.xx.3.xx:9300 admin 9ssspw  http-9300
  Can't locate XML/Simple.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at tomcatstats.pl line 7.
  BEGIN failed--compilation aborted at tomcatstats.pl line 7.
  
  需要安装XML::Simple
  [iyunv@squid-2 ~]# find / -name cpan
  /usr/bin/cpan
  [iyunv@squid-2 ~]# /usr/bin/cpan XML::Simple
  ……
  Prepending /root/.cpan/build/XML-Simple-2.20-7zpaOY/blib/arch /root/.cpan/build/XML-Simple-2.20-7zpaOY/blib/lib to PERL5LIB for 'install'
  Installing /usr/local/share/perl5/XML/Simple.pm
  Installing /usr/local/share/perl5/XML/Simple/FAQ.pod
  Installing /usr/local/share/man/man3/XML::Simple.3pm
  Installing /usr/local/share/man/man3/XML::Simple::FAQ.3pm
  Appending installation info to /usr/lib64/perl5/perllocal.pod
  GRANTM/XML-Simple-2.20.tar.gz
  /usr/bin/make install  -- OK
  Warning (usually harmless): 'YAML' not installed, will not store persistent state
  
  继续报错File does not exist:  at tomcatstats.pl line 20
  [iyunv@squid-2 scripts]# /usr/bin/perl tomcatstats.pl 10.254.3.29:9300 tomcat xxx   http-9300
  File does not exist:  at tomcatstats.pl line 20
  需要安装如下组件:
  [iyunv@squid-2 scripts]#yum install perl-HTML-Parser.i386 perl-HTML-Tagset.noarch perl-libwww-perl.noarch perl-URI.noarch
  
  之后启动tomcat报错如下:
  [tomcat@web-9 logs]$ cat catalina.out
  2014-6-6 15:11:15 org.apache.catalina.core.AprLifecycleListener init
  信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/jdk1.6.0_45/jre/lib/amd64/server:/usr/java/jdk1.6.0_45/jre/lib/amd64:/usr/java/jdk1.6.0_45/jre/../lib/amd64:/usr/local/lib::/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
  2014-6-6 15:11:16 org.apache.tomcat.util.digester.SetPropertiesRule begin
  警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'debug' to '0' did not find a matching property.
  
  跟踪后发现是连接池的配置问题:
  <Context path=&quot;/n&quot; docBase=&quot;server/webapps/manager &quot; debug=&quot;0&quot; reloadable=&quot;true&quot; crossContext=&quot;false&quot;>
  把debug=&quot;0&quot;去除即可。
  分析:tomcat的6.0.37这个版本中可能用别的属性替代了debug功能。
  
  6  Cacti监控tomcat的选项
  Graph templates,总共就4个选项,如下:
DSC0003.jpg

  
  
  点击监控项连接进去,看到RRDTool Says: ERROR: invalid y-grid format报错信息,
  解决办法是:
  进右上角的连接*Edit Graph Template --> Tomcat - Connection Rate --> Unit Grid Value (--unit/--y-grid),默认的值为1,去掉改成为0即可。
  同理解决Tomcat - Heap Statistics 不出图的问题 将1048576 值改空即可。
  之后如果10分钟内还是出不了图,那么可以继续等待,tomcat监控模板出图时间比较漫长,我这里等待了3个小时候后,图出来了,如下所示:
  1) Tomcat - Connection Rate     :连接效率
DSC0004.jpg


  2) Tomcat - Heap Statistics      : JVM堆得使用情况
DSC0005.jpg
  

  3) Tomcat - Thread Statistics    :线程状态
DSC0006.jpg

  
  4) Tomcat – Throughput        :Tomcat吞吐量
DSC0007.jpg


运维网声明 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-142181-1-1.html 上篇帖子: Cacti简易安装配置 下篇帖子: The Cacti Manual
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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