nagios 监控memcached 的方法及其配置
nagios 监控memcached 的方法分别有,
1 通过telnet来查看memcached 的状态
2 是通过nagios 的自己的插件httpd_tcp 来监控memcached
3通过Nagios-Plugins-Memcached 来监控memcached,
第一 通过telnet 来监控memcached
#telnet 192.168.2.186 11211
Trying 192.168.2.186...
Connected to 192.168.2.186 (192.168.2.186).
Escape character is '^]'.
stats
STAT pid 437
STAT uptime 74825
STAT time 1290149053
STAT version 1.4.5
STAT pointer_size 32
STAT rusage_user 0.006998
STAT rusage_system 0.017997
STAT curr_connections 5
STAT total_connections 52
STAT connection_structures 6
STAT cmd_get 0
STAT cmd_set 0
STAT cmd_flush 0
STAT get_hits 0
STAT get_misses 0
STAT delete_misses 0
STAT delete_hits 0
STAT incr_misses 0
STAT incr_hits 0
STAT decr_misses 0
STAT decr_hits 0
STAT cas_misses 0
STAT cas_hits 0
STAT cas_badval 0
STAT auth_cmds 0
STAT auth_errors 0
STAT bytes_read 348
STAT bytes_written 36417
STAT limit_maxbytes 419430400
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT threads 4
STAT conn_yields 0
STAT bytes 0
STAT curr_items 0
STAT total_items 0
STAT evictions 0
STAT reclaimed 0
END
这是通过telnet 监控memcached 的
第二.是用nagios的check_tcp 来进行监控memcached 但是他返回的信息和用上一种方法基本是像是
# check_tcp -H 192.168.2.186 -p 11211 -t 5 -E -s 'stats\r\nquit\r\n' -e 'uptime' -M crit
TCP OK - 0.002 second response time on port 11211 [STAT pid 437
STAT uptime 75179
STAT time 1290149407
STAT version 1.4.5
STAT pointer_size 32
STAT rusage_user 0.006998
STAT rusage_system 0.017997
STAT curr_connections 5
STAT total_connections 56
STAT connection_structures 7
STAT cmd_get 0
STAT cmd_set 0
STAT cmd_flush 0
STAT get_hits 0
STAT get_misses 0
STAT delete_misses 0
STAT delete_hits 0
STAT incr_misses 0
STAT incr_hits 0
STAT decr_misses 0
STAT decr_hits 0
STAT cas_misses 0
STAT cas_hits 0
STAT cas_badval 0
STAT auth_cmds 0
STAT auth_errors 0
STAT bytes_read 395
STAT bytes_written 38793
STAT limit_maxbytes 419430400
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT threads 4
STAT conn_yields 0
STAT bytes 0
STAT curr_items 0
STAT total_items 0
STAT evictions 0
STAT reclaimed 0
END]|time=0.002360s;;;0.000000;5.000000
再次没有定义在nagios的配置文件中,如果想用该方法监控memcached 的同时,需要定义一下该命令,才能应用该命令
第三 配置用Nagios-Plugins-Memcached 进行监控memcached。但是由于该插件是用prel 进行开发的所以系统上必须要安装Perl 环境,并且同时保证呢个该服务器能上网, cpanplugin 安装
CPAN的使用
默认情况下使用cpan命令安装时,如果依赖其他的软件包时cpan就会停止,但是如果使用CPANPLUS来进行安装时,就能能自动安装依赖项的模板
#cpan CPANPLUS
Are you ready for manual configuration? [yes]
CPAN build and cache directory? [/root/.cpan]
Cache size for build directory (in MB)? [10]
Perform cache scanning (atstart or never)? [atstart]
Cache metadata (yes/no)? [yes]
Your terminal expects ISO-8859-1 (yes/no)? [yes]
File to save your history? [/root/.cpan/histfile]
Number of lines to save? [100]
Policy on building prerequisites (follow, ask or ignore)? [ask]
Where is your gzip program? [/bin/gzip]
Where is your tar program? [/bin/tar]
Where is your unzip program? [/usr/bin/unzip]
Where is your make program? [/usr/bin/make]
Where is your links program? [/usr/bin/links]
Where is your wget program? [/usr/bin/wget]
Warning: ncftpget not found in PATH
Where is your ncftpget program? []
Warning: ncftp not found in PATH
Where is your ncftp program? []
Where is your ftp program? [/usr/kerberos/bin/ftp]
Where is your gpg program? [/usr/bin/gpg]
What is your favorite pager program? [/usr/bin/less]
What is your favorite shell? [/bin/bash]
Select your continent (or several nearby continents) [] 2 注: 这是选择地区
Select your country (or several nearby countries) [] 1 注:这选国家
2 首先下载Nagios-Plugins-Memcached-0.02.tar.gz,解压
#tar xvf Nagios-Plugins-Memcached-0.02.tar.gz
3 安装
#cd Nagios-Plugins-Memcached-0.0.2
#perl Makefile.pl
*** Module::AutoInstall version 1.03
*** Checking for Perl dependencies...
[Core Features]
- Carp::Clan
...missing.
- Cache::Memcached ...missing.
- FindBin
...loaded. (1.47)
- Nagios::Plugin ...missing.
- Time::HiRes
...loaded. (1.9717)
==> Auto-install the 3 mandatory module(s) from CPAN? [y]
#make install
4 查找安装后的check_memcached 的插件,并把该插件拷贝到nagios的插件的目录下面
#whereis check_memcached
#cp /usr/bin/check_memcached /usr/local/nagios/libexec
#chmod +x /usr/local/nagios/libexec/check_memcached
5 当然在用nagios 进行监控memcached 的方法方法分别是
首先定命令在nagios 命令文件command.cfg后面添加一下
define command{
command_name check_memcached_response
command_line $USER1$/check_memcached -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$
}
define command{
command_name check_memcached_size
command_line $USER1$/check_memcached -H $HOSTADDRESS$ --size-warning $ARG1$ --size-critical $ARG2$
}
define command{
command_name check_memcached_hit
command_line $USER1$/check_memcached -H $HOSTADDRESS$ --hit-warning $ARG1$ --hit-critical $ARG2$
}
6 定义主机
define host{
use linux-box-remote
host_name linux186
alias Memcache
address 192.168.2.186
}
define service{
use generic-service
host_name linux186
service_description Memcached
check_command check_memcached_response!30!40
}
define service{
use generic-service
host_name linux186
service_description Memcached_size
check_command check_memcached_size!30!40
}
define service{
use generic-service
host_name linux186
service_description Memcached_hit
check_command check_memcached_hit!40!30
}
#/usr/local/nagios/bin/nagio -v /usr/local/nagios/etc/nagios.cfg
检测配置文件是不是有错误,如果没有错误,并重启nagios
当然可以用nagios 的nrpe 进行监控memcached
本文转自 freehat08 51CTO博客,原文链接:http://blog.51cto.com/freehat/427585,如需转载请自行联系原作者