Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1653410
  • 博文数量: 135
  • 博客积分: 2820
  • 博客等级: 少校
  • 技术积分: 2544
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-16 13:33
文章分类

全部博文(135)

文章存档

2015年(1)

2014年(8)

2013年(16)

2012年(43)

2011年(56)

2010年(11)

分类: 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
# 文件名: monitormem.sh
# 用法: monitormem.sh 192.168.10.31 11211
exec 5<> /dev/tcp/$1/$2
if[$? -eq 0 ]; then
        echo"stats" >&5
        echo"quit" >&5
        while read -u 5 -d $'\r' stat name value;
        do
                echo$value
        done
        exit 0
fi
exit 1

二、需要netcat支持,脚本稍简单一点,原理都是一样的:

#!/bin/bash
# 文件名: monitormem.sh
# 用法: monitormem.sh 192.168.10.31 11211
echo -e "stats\nquit"|nc $1$2 | while read -d $'\r' stat name value;
do
        echo$value
done

Memcached-Tool,也挺好的:

简单的状态信息:

# Item_Size   Max_age 1MB_pages Count   Full?
1      96 B     3969 s       2   16384      no
2     120 B    77827 s     284 1798432      no

详细信息如下:

#192.168.10.31:11211 Field       Value
         accepting_conns               1
                         bytes                183861479
                  bytes_read                2492211350
               bytes_written                558827791
                  cas_badval                0
                     cas_hits                0
                cas_misses                 0
                    cmd_flush                0
                      cmd_get                28902205
                     cmd_set                30107902
                 conn_yields                529550
connection_structures                 17
        curr_connections                13
                   curr_items                1814816
                     decr_hits                0
                decr_misses                0
                   delete_hits                0
             delete_misses                0
                      evictions                0
                       get_hits                6139097
                  get_misses                22763108
                       incr_hits                0
                  incr_misses                0
              limit_maxbytes                10737418240
     listen_disabled_num                 0
                                 pid                3406
                 pointer_size                64
               rusage_system                381.562993
                   rusage_user                247.557365
                           threads                5
                                time               1274500838
          total_connections                 499
                      total_items                30107902
                            uptime                81526
                          version                1.4.0

Brutis的最大特点是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
ip=192.168.10.31

 

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
}

while [ 1 -eq 1 ];
do
        start=`get_hits`
        sleep 1
        end=get_hits`
        echo " $end - $start " | bc
done


阅读(3322) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~