Memcache stat command

Alexandre de Abreu alexandre.abreu at gmail.com
Thu Sep 29 13:00:45 PDT 2005


Hi all,

I've made a little bash script(below) for monitoring and generating
numbers for a Cacti server(rrd server), it's running well, but, has
anyone realized that 'stat' command outputs different than other
commands(control characters)?

Cheers

---------------------------------------8<----------------------------------------
#!/bin/bash
#
# Make a 'stat' command on a memcache daemon server
# Outputs to a pipe for later using with syslog-ng
#
# alexandre.abreu at gmail.com

PATH=/bin:/usr/bin:/sbin:/usr/sbin
SERVER=localhost
PORT=11111
FIFO=/export/logs/memcache.fifo
BUFF="memcache: "

[ -p $FIFO ] || mkfifo $FIFO || exit 1

exec 666<>/dev/tcp/$SERVER/$PORT || exit 1

append() {
    BUFF="$BUFF $@"
    [ "$1" == "uptime" ] && RUNTIME=`echo "scale=3; $2/60" | bc`

    [ "$1" == "get_hits" ] && {
        rate=`echo "scale=3; $2/$RUNTIME" | bc`
        rate=`printf "%.3f" $rate`
        append hitrate $rate
    }
    [ "$1" == "get_misses" ] && {
        rate=`echo "scale=3; $2/$RUNTIME" | bc`
        rate=`printf "%.3f" $rate`
        append missrate $rate
    }
}

echo "stats" >&666

while read line; do
    line=`echo $line | sed 's|[[:cntrl:]]||g'`
    set - $line
    append $2 $3
    [ "$2" == "limit_maxbytes" ] && break
done <&666

echo "$BUFF" > $FIFO
echo "quit" >&666
exit 0
---------------------------------------8<----------------------------------------

--
Alexandre de Abreu, GCUX, RHCE


More information about the memcached mailing list