Nagios监控Memcached服务

说到Memcached服务,其实作为运维人员用的还是很多的:

1、在做LB的时候,为了保证同一台机器的请求的session信息防止丢失,我们用Memcached对session做分布式存储。

2、做mysql缓存的时候,我们常常吧mysql查询的结果缓存到Memcached中,这样能够较少php程序与mysql的交互,也能大大减轻数据库的压力。

从以上来看,Memcached其实也是蛮重要的,那么我们更有必要对其进行时刻的监控,接下来引入正题

Nagios监控Memcached服务是否正常运行、Memcached内存的使用比例、Memcached是否应答等等

Cacti监控Memcached,请参考之前博文

http://467754239.blog.51cto.com/4878013/1433409



一、通过php页面来监测

下载memcache.php网页,然后发布这个页面后,通过浏览器访问

下载地址:

http://livebookmark.net/memcachephp/memcachephp.zip

http://blogimg.chinaunix.net/blog/upfile2/081230231118.zip

1、修改memcache.php部分参数

2、浏览器访问

注释:或许是memcached没有任何数据吧!

可是朋友的博客是这样的


二、利用Memcached自身的命令来检查

[root@lnmp ~]# telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is ‘^]‘.
stats
STAT pid 63992
STAT uptime 6204
STAT time 1412164192
STAT version 1.4.17
STAT libevent 2.0.21-stable
STAT pointer_size 64
STAT rusage_user 0.225965
STAT rusage_system 0.309952
STAT curr_connections 10
STAT total_connections 243
STAT connection_structures 12
STAT reserved_fds 20
STAT cmd_get 108
STAT cmd_set 43
STAT cmd_flush 0
STAT cmd_touch 0
STAT get_hits 68
STAT get_misses 40
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 touch_hits 0
STAT touch_misses 0
STAT auth_cmds 0
STAT auth_errors 0
STAT bytes_read 7326
STAT bytes_written 125489
STAT limit_maxbytes 67108864
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT threads 4
STAT conn_yields 0
STAT hash_power_level 16
STAT hash_bytes 524288
STAT hash_is_expanding 0
STAT malloc_fails 0
STAT bytes 205
STAT curr_items 2
STAT total_items 43
STAT expired_unfetched 0
STAT evicted_unfetched 0
STAT evictions 0
STAT reclaimed 0
END

或者利用nagios的check_tcp来监测,如下

[root@NagiosServer libexec]# ./check_tcp -H 192.168.0.12 -p 11211 -t 5 -E -s ‘stats\r\nquit\r\n‘ -e ‘uptime‘ -M crit
TCP OK - 0.001 second response time on 192.168.0.12 port 11211 [STAT pid 63992
STAT uptime 6295
STAT time 1412164283
STAT version 1.4.17
STAT libevent 2.0.21-stable
STAT pointer_size 64
STAT rusage_user 0.225965
STAT rusage_system 0.317951
STAT curr_connections 11
STAT total_connections 249
STAT connection_structures 12
STAT reserved_fds 20
STAT cmd_get 108
STAT cmd_set 43
STAT cmd_flush 0
STAT cmd_touch 0
STAT get_hits 68
STAT get_misses 40
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 touch_hits 0
STAT touch_misses 0
STAT auth_cmds 0
STAT auth_errors 0
STAT bytes_read 7374
STAT bytes_written 131873
STAT limit_maxbytes 67108864
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT threads 4
STAT conn_yields 0
STAT hash_power_level 16
STAT hash_bytes 524288
STAT hash_is_expanding 0
STAT malloc_fails 0
STAT bytes 205
STAT curr_items 2
STAT total_items 43
STAT expired_unfetched 0
STAT evicted_unfetched 0
S]|time=0.001293s;;;0.000000;5.000000


三、Nagios的check_memcached

下载地址:

http://www.filewatcher.com/m/Nagios-Plugins-Memcached-0.02.tar.gz.72-0.html

这个是perl写的脚本,所以在安装时需要支持perl环境,必先安装之

[root@NagiosServer ~]# yum -y install perl*
[root@NagiosServer ~]# tar xf Nagios-Plugins-Memcached-0.02.tar.gz
[root@NagiosServer Nagios-Plugins-Memcached-0.02]# cd Nagios-Plugins-Memcached-0.02
[root@NagiosServer ~]# perl Makefile.PL
[root@NagiosServer ~]# make && make install

做适应的修改

#默认check_memcached的安装路径
[root@NagiosServer ~]# find / -name check_memcached
/usr/local/bin/check_memcached

#对其进行适应的修改
[root@NagiosServer ~]# cp /usr/local/bin/check_memcached /usr/local/nagios/libexec/


四、Nagios对Memcached进行监控配置

1、定义命令

[root@NagiosServer objects]# vim commands.cfg 
#定义Memcached的内存使用比例
define command {
        command_name check_memcached_11211
        command_line $USER1$/check_memcached -H 192.168.0.12:11211 --size-warning 80 --size-critical 90
              }
#定义Memcached是否有应答
define command {
        command_name memcached_response_11211
        command_line $USER1$/check_memcached -H 192.168.0.12 -w 300 -c 500
               }
#定义Memcached的命中率
define command {
        command_name check_memcached_hit
        command_line $USER1$/check_memcached -H 192.168.0.12 --hit-warning 10 --size-critical 5
                }

2、定义服务和主机

define host{
        use                     linux-server
        host_name               Linux Server 02
        alias                   My Linux 02
        address                 192.168.0.12
        }
#define hostgroup{
#        hostgroup_name  admins
#        alias           Nagios Administrators
#        members         Linux Server 02
#        }
define service{
        use                             generic-service
        host_name                       Linux Server 02
        service_description             PING
        check_command                   check_ping!100.0,20%!500.0,60%
        }
define service{
        use                             generic-service
        host_name                       Linux Server 02
        service_description             Root Partition
        check_command                   check_local_disk!20%!10%!/
        }
define service{
        use                             generic-service
        host_name                       Linux Server 02
        service_description             Current Users
        check_command                   check_local_users!20!50
        }
define service{
        use                             generic-service
        host_name                       Linux Server 02
        service_description             Total Processes
        check_command                   check_local_procs!250!400!RSZDT
        }
define service{
        use                             generic-service
        host_name                       Linux Server 02
        service_description             Current Load
        check_command                   check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
        }
define service{
        use                             generic-service
        host_name                       Linux Server 02
        service_description             Swap Usage
        check_command                   check_local_swap!20!10
        }
define service{
        use                             generic-service
        host_name                       Linux Server 02
        service_description             SSH
        check_command                   check_ssh
        notifications_enabled           0
        }
define service{
        use                             generic-service
        host_name                       Linux Server 02
        service_description             HTTP
        check_command                   check_http
        notifications_enabled           0
        }

define service{
        use                             generic-service
        host_name                       Linux Server 02
        service_description             users
        check_command                   check_nrpe!check_users
        }
define service{
        use                             generic-service
        host_name                       Linux Server 02
        service_description             load
        check_command                   check_nrpe!check_load
        }
define service{
        use                             generic-service
        host_name                       Linux Server 02
        service_description             disk sda1
        check_command                   check_nrpe!check_sda1
        }
define service{
        use                             generic-service
        host_name                       Linux Server 02
        service_description             zombie_proces
        check_command                   check_nrpe!check_zombie_procs
        }
define service{
        use                             generic-service
        host_name                       Linux Server 02
        service_description             Total_proces
        check_command                   check_nrpe!check_total_procs
        }

define service{
        use                             generic-service
        host_name                       Linux Server 02
        service_description             Memcached Response 11211
        check_command                   check_memcached_11211
        }
define service{
        use                             generic-service
        host_name                       Linux Server 02
        service_description             Memcached memory
        check_command                   memcached_response_11211
        }
define service{
        use                             generic-service
        host_name                       Linux Server 02
        service_description             Memcached Hit
        check_command                   check_memcached_hit
        }

3、启用定义的主机配置文件

[root@NagiosServer etc]# vim nagios.cfg 
cfg_file=/usr/local/nagios/etc/objects/hosts/linux02.cfg

4、重新启动nagios服务

[root@NagiosServer ~]# service nagios restart
Running configuration check...
Stopping nagios: done.
Starting nagios: done.

五、查看页面监控结果

暂且就先到这里吧!更多的会在下一篇博文中写到



参考博文http://storysky.blog.51cto.com/628458/244962

本文出自 “郑彦生” 博客,请务必保留此出处http://467754239.blog.51cto.com/4878013/1560294

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。