如何监控MemCached的状态
使用MemCached以后,肯定希望知道cache的效果,对于MemCached的一些运行状态进行监控是必要的。MemCached也提供了stats接口输出一些信息,最简单的方式,就是telnet上去输入stats查看:
telnet 127.0.0.1 11211 Trying 127.0.0.1 ... Connected to memcache_test_host (127.0.0.1 ). Escape character is '^]'. stats STAT pid 7186 STAT uptime 1695 STAT time 1238401344 STAT version 1.2.6 STAT pointer_size 64 STAT rusage_user 0.003999 STAT rusage_system 0.002999 STAT curr_items 1 STAT total_items 54 STAT bytes 135 STAT curr_connections 2 STAT total_connections 111 STAT connection_structures 4 STAT cmd_get 3 STAT cmd_set 54 STAT get_hits 0 STAT get_misses 3 STAT evictions 0 STAT bytes_read 5957 STAT bytes_written 50914 STAT limit_maxbytes 2147483648 STAT threads 1 END
这种方式相当的不方便,所以网上就有各种不同客户端接口写的工具,比如用perl写的这个memcache-tool:
./memcached_tool
Usage: memcached-tool[mode] memcached-tool 10.0.0.5:11211 display # shows slabs memcached-tool 10.0.0.5:11211 # same. (default is display) memcached-tool 10.0.0.5:11211 stats # shows general stats memcached-tool 10.0.0.5:11211 move 7 9 # takes 1MB slab from class #7 # to class #9. You can only move slabs around once memory is totally allocated, and only once the target class is full. (So you can't move from #6 to #9 and #7 to #9 at the same itme, since you'd have to wait for #9 to fill from the first reassigned page) $ ./memcached_tool 127.0.0.1:11211 stats
#127.0.0.1:11211 Field Value bytes 135 bytes_read 5964 bytes_written 51394 cmd_get 3 cmd_set 54 connection_structures 4 curr_connections 3 curr_items 1 evictions 0 get_hits 0 get_misses 3 limit_maxbytes 2147483648 pid 7186 pointer_size 64 rusage_system 0.002999 rusage_user 0.003999 threads 1 time 1238401521 total_connections 112 total_items 54 uptime 1872 version 1.2.6
命令行的方式,在批处理调用的时候比较方便。但是在展现方面还是web方式更加直观有效,所以就有了php写的memcache.php,是的,用一次就知道这是我想要的。