前言:在内网环境监控外网ECS中的内网服务端口,试了几种方法都没成功,最后还是考虑用check_tcp来监控,输出命令信息,监控结果非常详细,很赞!分享给大家,希望对大家有所帮助。
一、check_tcp监控memcached
通过输入 stats 得到参数,输入quit 退出
因此可以利用check_tcp 来得到memcached的响应时间、uptime等信息,具体的命令格式如下:
/usr/local/nagios/libexec/check_tcp -H 192.168.2.11 -p 11211 -t 5 -E -s ‘stats\r\nquit\r\n‘ -e ‘uptime‘ -M crit
下面为命令的输出结果:呵呵够详细吧 更重要的是有了相应时间,而且你也可以对telnet 或 tcrmgr inform (远程管理工具,tcrmgr inform -port 11209 -st 192.168.2.9)结果进行各种过滤来得到想要的参数设置自己的阀值来做更详细的监控
TCP OK - 0.000 second response time on port 11211 [STAT pid 17689 STAT uptime 365034 STAT time 1432451978 STAT version 1.4.15 STAT libevent 1.4.13-stable STAT pointer_size 64 STAT rusage_user 7.746822 STAT rusage_system 4.885257 STAT curr_connections 5 STAT total_connections 20 STAT connection_structures 6 STAT reserved_fds 20 STAT cmd_get 0 STAT cmd_set 0 STAT cmd_flush 0 STAT cmd_touch 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 touch_hits 0 STAT touch_misses 0 STAT auth_cmds 0 STAT auth_errors 0 STAT bytes_read 89 STAT bytes_written 4140 STAT limit_maxbytes 2621440000 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 bytes 0 STAT curr_items 0 STAT total_items 0 STAT expired_unfetched 0 STAT evicted_unfetched 0 STAT evictions 0 STAT reclaimed]|time=0.000413s;;;0.000000;5.000000
加入到nrpe.cfg 里面
command[check_memcached_11211]=/usr/local/nagios/libexec/check_tcp -H 192.168.2.11 -p 11211 -t 5 -E -s ‘stats\r\nquit\r\n‘ -e ‘uptime‘ -M crit
二、check_tcp监控redis
redis 不支持 stats 需要改成info 命令格式和上面一样
/usr/local/nagios/libexec/check_tcp -H 192.168.2.11 -p 6379 -t 5 -E -s ‘info\r\nquit\r\n‘ -e ‘uptime‘ -M crit