Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3017107
  • 博文数量: 535
  • 博客积分: 15788
  • 博客等级: 上将
  • 技术积分: 6507
  • 用 户 组: 普通用户
  • 注册时间: 2007-03-07 09:11
文章分类

全部博文(535)

文章存档

2016年(1)

2015年(1)

2014年(10)

2013年(26)

2012年(43)

2011年(86)

2010年(76)

2009年(136)

2008年(97)

2007年(59)

分类: LINUX

2011-02-12 11:10:03

一 memcached
This template provides a host template and associated graphs for graphing the output of the stats command on individual installations.

Graphs are provided for Bytes Used with total capacity, Cache Hits and Misses per second, Current Connections, Items Cached, Inbound and Outbound Network Traffic (bits per second), and Requests per Second for both the get and set commands.

The latest version and installation instructions can be found at http://dealnews.com/developers/cacti/memcached.html.

cacti服务器使用python的memcached客户端,通过执行memcached stats command 来获取数据。

1、下载并安装memcached的pythoh客户端
ftp://ftp.tummy.com/pub/python-memcached/
当前版本:ftp://ftp.tummy.com/pub/python-memcached/python-memcached-1.47.tar.gz
  
安装:
tar -xvzf python-memcached-1.47.tar.gz
  1. [root@111 python-memcached-1.47]# python setup.py install
  2. Traceback (most recent call last):
  3. File "setup.py", line 3, in ?
  4. from setuptools import setup
  5. ImportError: No module named setuptools
缺少python的setuptools模块:
模块地址:
python -v 查看python版本
下载对应版本的模块:2.4
        
安装: ./setuptools-0.6c11-py2.4.egg

setuptools安装完成,再次安装memcache client
python setup.py install

2、安装cacti模板
下载:http://s1.dlnws.com/dealnews/developers/cacti-memcached-1.0.tar.gz
  tar -xvzf cacti-memcached-1.0.tar.gz
cp memcached.py /scripts/ 
注:端口非11211? 修改该文件

测试:
python //scripts/memcached.py 192.168.1.11
  1. total_items:177745693 get_hits:9646440970 uptime:24449942 cmd_get:9816729275 time:1297481502 bytes:17871442 curr_connections:118 connection_structures:1187 bytes_written:2234868242829 limit_maxbytes:838860800 cmd_set:177748658 curr_items:46090 rusage_user:42798.648616 get_misses:170288305 rusage_system:133395.413814 bytes_read:353584260005 total_connections:175559625
打开cacti的consol,Import Templates,选择cacti_memcached_host_template.xml

3、为相应的服务器添加绘图
  服务器ID为公网IP,而memcache监听在内网IP?
 cacti console ->Data Templates->Host to query for memcached statistics.
勾选 Use Per-Data Source Value (Ignore this Value)

   修改相应的服务器的Data SourcesHost to query for memcached statistics.添写内部ip

二 tomcat

数据来源:使用脚本,获取tomcat manager的数据。
下载模板及脚本: ,或从本blog下载: TomcatStats-0.1.zip   

1、配置tomcat
打开tomcat的manager
修改tomcat-usr.xml文件:
restart tomcat 
?XML=true

2、配置cacti
     (1)确保安装了需要的 XML::Simple模块
       perl -MCPAN -e"install XML::Simple"
    (2)拷贝tomcatstats.pl脚本到/scripts/
     (3) 测试脚本
./tomcatstats.pl 1.1.1.1:8080 admin password http-8080
  1. jvm_memory_free:453432112 jvm_memory_max:932118528 jvm_memory_total:837353472 
  2. connector_max_time:1008 connector_error_count:26 connector_bytes_sent:16899331953
  3. connector_processing_time:4441262 connector_request_count:3714312
  4. connector_bytes_received:0 connector_current_thread_count:64 
  5. connector_min_spare_threads: connector_max_threads:1000 
  6. connector_max_spare_threads: connector_current_threads_busy:1
其中http-8080是你要监控的tomcat的connector,一般是http-8080,可以通过下图看出

(4)导入cacti模板
A. Import the cacti_host_template_tomcat_server.xml into Cacti          B. If you used a password other than "passwords" or need to monitor a different connector:       Modify "Data Input Methods:Tomcat Status:Input String" as needed.
(5) 绘图
关于图片下面的注释,可以通过下面的方法修改或移除:
 
  关于:Heap Statistics,不出图
打开data source中的debug,可以看到错误:
RRDTool Says:
ERROR: invalid y-grid format  
 解决办法:Templates->Tomcat - Heap Statistics->Unit Grid Value (--unit/--y-grid) ,将已经填入的值1048576清空
connection rate也不出图?按照上面的方法,清空已经填入的值


不能出图?
手动运行脚本,能够正常出数据,但是当poller为spine时,output却为0.
debug:
 /usr/local/spine/bin/spine -C /usr/local/spine/etc/spine.conf --verbosity=5 -H 3
其中-H 3为指定host,host的ID可以在device中看到。
问题出在输出的数据的格式上,去掉每行print后面的空格和回车。

用于短信报警:
  1. #!/usr/bin/perl
  2. #use strict;
  3. use XML::Simple;
  4. use Date::Format;
  5. use Date::Parse;
  6. sub current_time {
  7. time2str("%Y%m%d-%T",str2time(ctime(time)))
  8. };
  9. my $host = "1.1.1.17:8080";
  10. my $username = "admin";
  11. my $password = "admin";
  12. my $connector = "http-8080";
  13. my $url = ""."\@$host/manager/status?XML=true";
  14. my $xml = `GET $url`;
  15. my $status = XMLin($xml);
  16. $threads_count="$status->{connector}->{$connector}->{threadInfo}->{currentThreadCount}" ;
  17. open $html,">","/usr/local/nginx/html/threats.html" or die $i;
  18. ( $threads_count > 800 )?print $html current_time().": false":print $html current_time().": ok";
上面的GET
我没有找到出自哪个RPM包,所以用下面的方法处理:
源自:
将bin目录下的lwp-request文件拷贝到/usr/bin目录下了
cp ./bin/lwp-request /usr/bin/GET
阅读(4122) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

网络安全服务2011-05-11 16:45:43

细心么```