首页 > 互联网技术 > 使用 libmemcached和监控memcached

使用 libmemcached和监控memcached

2010年5月5日 2,985 views 发表评论 阅读评论

1.使用 libmemcached

php,perl等语言可以使用自带的客户端,也可以使用Libmemcached实现访问memcached.

The libmemcached library provides both C and C++ interfaces to memcached and is also the basis for a number of different additional
API implementations, including Perl, Python and Ruby. Understanding the core libmemcached functions can help when using
these other interfaces.
下载.libmemcached
最新版本不太好编译   #我的os rhel4.7 32bit
注意先安装memcached,否则编译出错.configure: error: “could not find memcached binary”
故安装0.3版本.https://launchpad.net/libmemcached/+milestone/0.30
./configure –prefix=/home/garychen/app/libmemcached-0.3
make -j 4
make install
安装成功,测试memstat命令,成功.
主要的命令如下:
The main tools are:
memcat — display the value for each ID given on the command line:
shell> memcat –servers=localhost hwkey
Hello world
./memcat –server=127.0.0.1:11211 garychen
good_job
memcp — copy the contents of a file into the cache, using the file names as the key:
memrm — remove an item from the cache:
memslap — test the load on one or more memcached servers, simulating get/set and multiple client operations. For example, you can simulate the load of 100 clients performing get operations:
memflush — flush (empty) the contents of the memcached cache.
[garychen@testserver bin]$ ./memstat –server  192.168.30.39:11211,127.0.0.1:11211
Listing 2 Server
Server: 192.168.30.39 (11211)
pid: 32093
uptime: 12532581
time: 1273044824
version: 1.2.8
pointer_size: 32
rusage_user: 5196.773970
rusage_system: 20104.848598
curr_items: 9528243
total_items: 137537359
bytes: 1936390335
curr_connections: 385
total_connections: 21008404
connection_structures: 762
cmd_get: 622877923
cmd_set: 137537359
get_hits: 557826477
get_misses: 65051446
evictions: 64802320
bytes_read: 1936390335
bytes_written: 1936390335
limit_maxbytes: 2147483648
threads: 2
Server: 127.0.0.1 (11211)
pid: 4777
uptime: 6385
time: 1273044820
version: 1.4.4
pointer_size: 32
rusage_user: 0.0
rusage_system: 0.1999
curr_items: 0
total_items: 0
bytes: 0
curr_connections: 10
total_connections: 15
connection_structures: 11
cmd_get: 0
cmd_set: 0
get_hits: 0
get_misses: 0
evictions: 0
bytes_read: 0
bytes_written: 0
limit_maxbytes: 1073741824
threads: 4
2. 监控memcached server,收集memcached信息.
我们可以编写一个脚本,遍历本集群所有memcached,收集信息,报警监控…
也可利用下面的工具,更方便编写脚本..
memcached的创造着Brad写的名为memcached-tool的Perl脚本,可以方便地获得slab的使用情况
http://code.sixapart.com/svn/memcached/trunk/server/scripts/memcached-tool
http://tech.idv2.com/2008/07/11/memcached-002/  有介绍.
/home/garychen/app/libmemcached-0.3/bin/memcached-tool.pl    #不带参数直接输入,显示帮助.
参考网上有介绍的一个php的脚本.图形化展示memcached的性能和统计.
总结这个php脚本的memcache 的一些计算如下. 有不足之处.
[wearerss@testserver3 htdocs]$ telnet 127.0.0.1 11211
Trying 127.0.0.1…
Connected to localhost.localdomain (127.0.0.1).
Escape character is ‘^]’.
stats
STAT pid 32093
STAT uptime 12535400                  #startTime  运行以来的时间 20周.
STAT time 1273047643                  # 当前unix时间戳
STAT version 1.2.8
STAT pointer_size 32
STAT rusage_user 5197.251897
STAT rusage_system 20106.652324
STAT curr_items 9528216
STAT total_items 137545445
STAT bytes 1936608127
STAT curr_connections 389
STAT total_connections 21008738
STAT connection_structures 762
STAT cmd_flush 0
STAT cmd_get 622969373
STAT cmd_set 137545445
STAT get_hits 557910195
STAT get_misses 65059178
STAT evictions 64803871
STAT bytes_read 89871060602
STAT bytes_written 777502774506
STAT limit_maxbytes 2147483648
STAT threads 2
STAT accepting_conns 1
STAT listen_disabled_num 0
END
关于free内存
Free:limit_maxbytes 2147483648-STAT bytes 1936608127=201M    #实际上这个值不太靠谱.我想memcached自身的管理,元数据等也需要占用内存,空闲201M,可能意味着根本没有空闲内存了.
使用的内存
Used:STAT bytes 1936608127=1846M=1.9G
命中率:
Hits:hits*100/($hits+$misses))
请求频率 Request Rate (hits, misses)
($hits+$misses)/启动以来的秒数
Hit Rate 略
Miss Rate 略
Set Rate 略
参考:
 » 如果喜欢可以: 点此订阅本站
分类: 互联网技术 标签: ,
  1. godsmemory
    2010年6月30日00:14 | #1

    哈哈,老陈威武!

  1. 本文目前尚无任何 trackbacks 和 pingbacks.