分类: LINUX
2012-10-23 17:48:01
http://hi.baidu.com/higkoo/blog/item/1a7aedb1fed499580823021d.html
市面上Memcached监控工具好多,譬如:
1、memcached.php
2、memcached-tool:
3、Brutis:
4、像Cacti 之类大型的监控系统也能支持:
5、telnet
外表在华丽,最终都是从Memcached的stats里拿到的数据,然后包装一下(包装其实也很重要!)。
最原始的方法是使用Telnet连接:
譬如:telnet 192.168.10.31 11211
然后输入stats回车,会拿到类似如下的信息:
STAT pid 3306
STAT uptime 80456
STAT time 1274499768
STAT version 1.4.0
STAT pointer_size 64
STAT rusage_user 247.557365
STAT rusage_system 381.562993
STAT curr_connections 12
STAT total_connections 495
STAT connection_structures 17
STAT cmd_get 28902205
STAT cmd_set 30107902
STAT cmd_flush 0
STAT get_hits 6139097
STAT get_misses 22763108
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 bytes_read 2492211224
STAT bytes_written 558817585
STAT limit_maxbytes 107374182
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT threads 5
STAT conn_yields 529550
STAT bytes 183861479
STAT curr_items 1814816
STAT total_items 30107902
STAT evictions 0
END
这里介绍Bash Shel版本的监控方法:
一、原生态,绝大多数Linux/Unix都支持的方法:
#!/bin/bash二、需要netcat支持,脚本稍简单一点,原理都是一样的:
#!/bin/bashMemcached-Tool,也挺好的:
简单的状态信息:
# Item_Size Max_age 1MB_pages Count Full?详细信息如下:
#192.168.10.31:11211 Field ValueBrutis的最大特点是Ops/sec等指标是以秒为单位进行差量计算得到,其它如Memcached.php是累积数据。截图:
Brutis 2 Connections
Type Ops/sec Hits/sec Misses/sec Fails/sec Latency MB/sec
-------------------------------------------------------------------------------
Sets: 119.00 --- --- 0.00 0.000797 0.03
Gets: 1,189.98 208.60 981.38 0.00 0.000723 0.05
Totals: 1,308.98 208.60 981.38 0.00 0.000760 0.08
-------------------------------------------------------------------------------
SETS GETS
-------------------------------------------------------------------------------
Host Ops/sec Latency MB/sec Ops/sec Latency MB/sec
-------------------------------------------------------------------------------
higkoo.net 119.00 0.000797 0.03 1,189.98 0.000723 3.05
memcached.php截图:
OK,这里我们来写一个简单的监控Memcached点击率的Shell脚本:
#!/bin/bash
get_hits(){
exec 5<> /dev/tcp/$ip/11211
if [ $? -eq 0 ]; then
echo "stats" >&5
echo "quit" >&5
while read -u 5 -d $'\r' stat name value;
do
if [ $name == 'get_hits' ];then
echo $value
break
fi
done
fi
}