|
下载tomcat模版 TomcatStats-0.1
解压之后,修改tomcatstats.pl
my $url = "http://$username:$password"."@$host/manager/status?XML=true";
my $xml = `GET $url`;
替换以下两行为:
my $url = "http://$host/manager/status?XML=true";
my $xml = `wget -qO - --http-user=$username --http-password=$password $url`;
修改之后把脚本放在cacti/scripts下面。
然后把模版导入到cacti
配置tomcat
编辑tomcat/conf/tomcat-users.xml
添加以下行:
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user username="test" password="123" roles="manager-gui,manager-script,manager-jmx,manager-status"/>
重启tomcat。这里要注意要确保在浏览器里面打开http://xxx:8080/manager然后能正常登录,不然测试的时候会报下面的错误:
File does not exist: at tomcatstats.pl line 20.
在cacti服务端安装以下软件包
yum install perl-HTML-Parser perl-HTML-Tagset perl-libwww-perl perl-URI
如果还报下面的错误:
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.
请执行下面的命令:
cpan install XML::Simple
安装完毕后在cacti服务端测试:
[iyunv@osa scripts]# perl tomcatstats.pl 192.168.0.86:8086 apabi Founder123 \"http-nio-8086\"
jvm_memory_free:1591783944 jvm_memory_max:22543335424 jvm_memory_total:2186805248 connector_max_time:105 connector_error_count:7 connector_bytes_sent:157617 connector_processing_time:2169 connector_request_count:1345 connector_bytes_received:0 connector_current_thread_count:25 connector_min_spare_threads: connector_max_threads:2000 connector_max_spare_threads: connector_current_threads_busy:1
注意:tomcat8默认http的connector名称为http-nio-8086,tomcat7默认的http的connector名称为http-bio-8090,tomcat6的是http-8080,而且tomcat的http-nio-8086的双引号在perl中要转义才能被解析,否则出现只有jvm相关数据,其他connector没有数据.
比如下面的报错:
jvm_memory_free:1759299736 jvm_memory_max:22543335424 jvm_memory_total:2186805248 connector_max_time: connector_error_count: connector_bytes_sent: connector_processing_time: connector_request_count: connector_bytes_received: connector_current_thread_count: connector_min_spare_threads: connector_max_threads: connector_max_spare_threads: connector_current_threads_busy:
配置完毕后在管理页面添加监控就好了。
下面一篇文章将介绍cacti监控多个多端口tomcat
|
|