cacti监控tomcat-创新互联

环境:

成都网站制作、做网站介绍好的网站是理念、设计和技术的结合。成都创新互联公司拥有的网站设计理念、多方位的设计风格、经验丰富的设计团队。提供PC端+手机端网站建设,用营销思维进行网站设计、采用先进技术开源代码、注重用户体验与SEO基础,将技术与创意整合到网站之中,以契合客户的方式做到创意性的视觉化效果。

tomcat:apache-tomcat-7.0.35

cactiEZ:10.1

系统:centos5.6_x64

一、配置tomcat服务器

1、添加账号

vim tomcat-users.xml





重启tomcat

2、安装snmp协议

yum -y install net-snmp

vim /etc/snmp/snmpd.conf

com2sec notConfigUser default public

view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc

view all included .1      80

access notConfigGroup "" any noauth exact all none none

/etc/rc.d/init.d/snmpd restart

3、测试snmp

测试本机:snmpwalk -c public -v 2c localhost

测试远程主机:snmpwalk  -V 2c -C public -H 192.168.1.133 -L

二、配置cactiEZ

安装 XML::Simple模块

安装方法: (perl -MCPAN -e "install XML::Simple")

三、下载模板,导入模板

1、载监控tomcat的模板

TomcatStats-0.1.zip

2、修改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`;

说明:此处的-qO中的O为大写字母欧O;不然在你导入之后很可能出现数据出不来。

4、导入模板(cacti_host_template_tomcat_server.xml)

进入cacti --< Console(控制台) ---< Import Templates(导入模板)

5、上传监控脚本

将tomcatstats.pl上传放到cactiEZ服务器的/var/www/html/scripts目录下。

四、测试脚本

#/usr/bin/perl tomcatstats.pl 192.168.1.201:8080 admin 123 \"http-bio-8080\"

jvm_memory_free:9029383656 jvm_memory_max:9963962368 jvm_memory_total:9963962368 connector_max_time:75 connector_error_count:4 connector_bytes_sent:14896 connector_processing_time:104 connector_request_count:7 connector_bytes_received:0 connector_current_thread_count:11 connector_max_threads:1000 connector_current_threads_busy:1 [root@CactiEZ scripts]#

1、如果提示:-bash: ./tomcatstats.pl: /usr/bin/perl^M: bad interpreter: No such file

编辑tomcatstats.pl,将首行改为:#!/usr/bin/perl -w (加上-w)

2、如果提示:File does not exist:  at ./tomcatstats.pl line 21(21行是:my $status = XMLin($xml);)

说明无法得到远程tomcat服务器数据,检查tomcat配置的用户是否生效。

3、如果输出只有jvm数据,如:

jvm_memory_free:9441488 jvm_memory_max:85196800 jvm_memory_total:23777280 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: [root@CactiEZ scripts]

则要注意测试命令和tomcat版本。

网上朋友解释为:

Tomcat7的默认的http的connector名称为http-bio-8090,tomcat6的是http-8080,而且tomcat的http-bio-8090的双引号在perl中要转义才能被解析,否则出现只有jvm相关数据,其他connector没有数据。

五、配置cactiEZ

进入cacti---< console (控制台)--< Data Input Methods(数据输入方法) ---< Tomcat Status

修改Input String(输入字符串)

perl /scripts/tomcatstats.pl :8444 admin passwords http-8080

修改为:

perl /scripts/tomcatstats.pl :8080 admin 123 \"http-bio-8080\"

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网页名称:cacti监控tomcat-创新互联
文章出自:http://myzitong.com/article/dpcdih.html