用telnet测试memcached

memcached如何清理缓存?

telnet上去之后 使用命令 flush_all 即可!

 

 

一、缓存命中率 = get_hits/cmd_get * 100%
二、get_misses的数字加上get_hits应该等于cmd_get
三、total_items == cmd_set == get_misses,当可用最大内存用光时,
memcached就会删掉一些内容,等式就会不成立

 

 

 

用telnet测试memcached

telnet 127.0.0.1 11211
Trying 127.0.0.1…
Connected to zou.yunhao (127.0.0.1).
Escape character is ‘^]’.
set key 0 10 6   //10表示过期时间10秒,6表示将要存入数据字节为6(这里result为6)
result
STORED
get key
VALUE key 0 6
result
END
4)memcached性能查看命令stats
telnet 127.0.0.1 11211
stats
STAT pid 18006
STAT uptime 702   //memcached运行的秒数
STAT time 1292904537 //memcached服务器所在主机当前系统的时间,单位是秒。
STAT version 1.4.5
STAT pointer_size 64  //服务器所在主机操作系统的指针大小,一般为32或64
STAT rusage_user 0.003999
STAT rusage_system 0.013997
STAT curr_connections 10   //表示当前的连接数
STAT total_connections 11   //表示从memcached服务启动到当前时间,系统打开过的连接的总数。
STAT connection_structures 11  //服务器分配的连接构造数
STAT cmd_get 0   //查询缓存的次数,平均每秒缓存次数cmd_get/uptime
STAT cmd_set 0   //设置key=>value的次数
STAT cmd_flush 0
STAT get_hits 0  //缓存命中的次数,缓存命中率=get_hits/cmd_get*100%
STAT get_misses 0  //cmd_get-get_hits
STAT delete_misses 0   delete未命中次数
STAT delete_hits 0    delete命中次数
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 7  //memcached服务器从网络读取的总的字节数
STAT bytes_written 0  //memcached服务器发送到网络的总的字节数。
STAT limit_maxbytes 67108864  //memcached服务缓存允许使用的最大字节数  分配给memcache的内存大小(字节)
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT threads 4  当前线程数
STAT conn_yields 0
STAT bytes 0
STAT curr_items 0  服务器当前存储的items数量
STAT total_items 0  从服务器启动以后存储的items总数量
STAT evictions 0  为获取空闲内存而删除的items数(分配给memcache的空间用满后需要删除旧的items来得到空间分配给新的items)
STAT reclaimed 0
END
 

STAT pid 1253
STAT uptime 76637
STAT time 1305776802
STAT version 1.4.5
STAT pointer_size 32
STAT rusage_user 2.339644
STAT rusage_system 14.290827
STAT curr_connections 5
STAT total_connections 88669
STAT connection_structures 79
STAT cmd_get 88660
STAT cmd_set 88661
STAT cmd_flush 0
STAT get_hits 73875
STAT get_misses 14785
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 79554683
STAT bytes_written 65724855
STAT limit_maxbytes 10485760
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT threads 4
STAT conn_yields 0
STAT bytes 4149748
STAT curr_items 5171
STAT total_items 88660
STAT evictions 0
STAT reclaimed 9610
-------------------------------
 

[root@jushanweb1 ~]# telnet 192.168.12.201 13002
Trying 192.168.12.201...
Connected to 192.168.12.201 (192.168.12.201).
Escape character is '^]'.
stats
STAT pid 8382
STAT uptime 190574
STAT time 1301579774
STAT version 1.2.0
STAT pointer_size 32
STAT rusage_user 0.003999
STAT rusage_system 0.033994
STAT curr_items 1
STAT total_items 1
STAT bytes 50
STAT curr_connections 2
STAT total_connections 4
STAT connection_structures 3
STAT cmd_get 0
STAT cmd_set 1
STAT get_hits 0
STAT get_misses 0
STAT bytes_read 216
STAT bytes_written 92
STAT limit_maxbytes 524288000
END

 
 
监控
1)nagios监控
a. check_memcached
先要安装check_memcached插件
wget http://search.cpan.org/CPAN/authors/id/Z/ZI/ZIGOROU/Nagios-Plugins-Memcached-0.02.tar.gz
tar xzvf Nagios-Plugins-Memcached-0.02.tar.gz
cd Nagios-Plugins-Memcached-0.02
perl Makefile.PL   (可能需要其他perl的modules,依照提示通过cpan安装即可)
make && make install
check_memcached [-H host:port] [-w warnings] [-c critical] [--size-warnng size-warnng] [--size-critical size-critical] [--hit-warning hit-warning] [--hit-critical
hit-critical] [-t timeout]
b. /check_tcp -H host -p 11211 -t 5 -E -s ‘stats\r\nquit\r\n’ -e ‘uptime’ -M crit
2)cacti监控
一台服务器起多个memcached,多端口cacti部署监控。
a. 需要一个 Python memcached Client API
wget ftp://ftp.tummy.com/pub/python-memcached/python-memcached-1.45.tar.gz
tar xzvf python-memcached-1.45.tar.gz
cd python-memcached-1.45
python setup.py install
b. 加模板memcached multiport
wget http://tag1consulting.com/blog/cacti-memcache-multi-port-templates
cp memcached.py   <cacti install目录>/scripts/memcachedmultiport.py
c. 增加监控时devices->des && ip->host template选择memcachedmultiport->Downed Device Detection选择none->SNMP Version选择not in use->create graphs->Port to query for memcached statistics填写memcached端口。
3)也可以自定义nagios、cacti监控,通过memcached命令stats取相关数据。
posted on 2013-03-07 19:41  smartch  阅读(903)  评论(0编辑  收藏  举报