Cacti監控Tomcat伺服器實現過程

來源:互聯網
上載者:User

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模板。
3 cacti伺服器端載入tomcatstats.pl統計指令碼

將解壓縮TomcatStats-0.1.zip 得到的tomcatstats.pl 放到/var/www/html/cacti/scritps 目錄下,並且賦予執行許可權<喎?http://www.bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vcD48cD5DaG93biCoQ1IgYXBhY2hlLmFwYWNoZSB0b21jYXRzdGF0cy5wbDwvcD48cD5jaG1vZCA3NTUgdG9tY2F0c3RhdHMucGw8L3A+PHA+0N64xHRvbWNhdHN0YXRzLnBso6y087jFtdoyMNDQo6y9qzwvcD48cD4xLiAgICAgIG15ICR4bWwgPSBgR0VUICR1cmxgOzwvcD48cD7Q3rjEzqo8L3A+PHA+MS4gICAgICBteSAkeG1sID0gYHdnZXQgLXFPIC0gJHVybGA7PC9wPjxwPrK7yLvU2sTjtbzI69auuvO63L/JxNyz9s/Wyv2+3bP2srvAtKGjPC9wPjxwPkNoZWNrIFVSTMGsvdPKx7fx1f3ItzwvcD48cD5WaW0gdG9tY2F0c3RhdHMucGwguvOjrNTatdoxN9DQuvPD5sztvNNwcmludCAkdXJso6zU2r/Y1sbMqLTys/Z1cmyjrMjnz8LL+cq+o7ogICA8L3A+PHA+bXkgJHVybCA9ICZxdW90O2h0dHA6Ly8kdXNlcm5hbWU6JHBhc3N3b3JkJnF1b3Q7LiZxdW90O1xAJGhvc3QvbWFuYWdlci9zdGF0dXM/WE1MPXRydWUmcXVvdDs7PC9wPjxwPnByaW50ICR1cmw7PC9wPjxwPnByaW50IKGwICAgobE7PC9wPjxwPiA8L3A+PHA+yLu689PDcGVybMC0Y2hlY2vPws2zvMa9xbG+o6zI58/Co7o8L3A+PHA+W3Jvb3RAc3F1aWQtMiBzY3JpcHRzXSMgcGVybCB0b21jYXRzdGF0cy5wbCAxMC54eC4zLnh4Ojk0NDQg"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的統計資訊,如下所示:

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 介紹,如:

5 web端tomcat伺服器的配置調整

在tomcat/conf/server.xml 裡面添加如下:

<Service name="Admin">

<Connector port="9444" 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="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>

然後在tomcat/conf/tomcat-users.xml裡面 添加

<role rolename="manager-gui"/>

<user username="tomcat" password="9ssspw " roles="manager-gui"/>

passwords 為串連密碼 可自行更改,然後重啟tomcat 服務

去cacti伺服器端執行perl tomcatstats.pl 10.xx.3.xx:9444 "tomcat' '9ssspw ' http-9444 check統計指令碼是否能取到tomcat的資料,有資料即正常,如下所示:

[root@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

[root@squid-2 scripts]#

記錄debug期間的報錯資訊如下:

[root@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

[root@squid-2 ~]# find / -name cpan

/usr/bin/cpan

[root@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

[root@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

需要安裝如下組件:

[root@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="/n" docBase="server/webapps/manager " debug="0" reloadable="true" crossContext="false">

把debug="0"去除即可。

分析:tomcat的6.0.37這個版本中可能用別的屬性替代了debug功能。

6 Cacti監控tomcat的選項

Graph templates,總共就4個選項,如下:

點擊監控項串連進去,看到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 :串連效率

2) Tomcat - Heap Statistics : JVM堆得使用方式


3) Tomcat - Thread Statistics :線程狀態

4) Tomcat – Throughput :Tomcat輸送量

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.