Memcached の容量を監視する

Cache::Memcached を利用して Memcached を利用していますが、
容量を監視したいと思ったときに エラー(容量が一杯によりset失敗とか)をハンドリングする方法がないようでした。(知らないだけ?)
どうにか容量を監視できないかなぁということで、memcachedサーバのソースに同梱しているスクリプトを見つけました。


監視スクリプト

memcached/scripts/memcached-tool


USAGE

# ./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 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 localhost:11211 display
 # Item_Size  Max_age  1MB_pages Full?
 6      64 B      0 s       1      no
 7     128 B      0 s       1      no
 8     256 B      0 s       1      no
 9     512 B      0 s       1      no
 10      1 kB      0 s       1      no
 11      2 kB      0 s       1      no
 12      4 kB      0 s       1      no
 13      8 kB      0 s       1      no
 14     16 kB      0 s       1      no
 15     32 kB      0 s       1      no
 16     64 kB      0 s       1      no
 17    128 kB      0 s       1      no


このスクリプトを利用して cron等 で定期的にデータを採取すると、Memcachedの容量を監視できてステキですね。