最近写了一个简单的监控memcached流量的shell,希望对大家有帮助。
使用方法很简单 直接更跟IPADDR变量即可。
- #!/bin/sh
-
# By zongzhuangkai
-
# 2011/06/04
-
-
while :
-
do
-
#var
-
if [ -e $1 ]
-
then
-
IPADDR=$1
-
IPADDR=8.8.8.8
-
else
-
IPADDR=$1
-
fi
-
PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
-
export PATH
-
-
read_mem_first=`cat /tmp/read_mem_first`
-
write_mem_first=`cat /tmp/write_mem_first`
-
read_mem_r=`echo "stats" | nc $IPADDR 12000 |awk '$2 ~ /bytes_read/{print $3}' |cat -v | sed 's/\^M//g'`
-
write_mem_w=`echo "stats" | nc $IPADDR 12000 |awk '$2 ~ /bytes_written/{print $3}' |cat -v | sed 's/\^M//g'`
-
read_mem_total=`expr \( $read_mem_r - $read_mem_first \) / 1024`
-
write_mem_total=`expr \( $write_mem_w - $write_mem_first \) / 1024`
-
total_mem_wr=`expr $read_mem_total + $write_mem_total`
-
echo "stats" | nc $IPADDR 12000 |awk '$2 ~ /bytes_read/{print $3}' |cat -v | sed 's/\^M//g' > /tmp/read_mem_first
-
echo "stats" | nc $IPADDR 12000 |awk '$2 ~ /bytes_written/{print $3}' |cat -v | sed 's/\^M//g' > /tmp/write_mem_first
-
echo "IP : $IPADDR"
-
echo "read kb :" $read_mem_total
-
echo "write kb :" $write_mem_total
-
echo "total kb :" $total_mem_wr
-
sleep 0.8
-
clear
-
done
阅读(938) | 评论(0) | 转发(0) |