Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Pipe memcache stats into Graphite
if [ "$1" != "report" ]; then
echo "Usage:" >&2
script="`basename $0`"
echo " nohup $script report > /var/log/memcache-stats.log &" >&2
exit 1
while true; do
# Do it in a backgrounded subshell so we can move
# directly on to sleeping for $GRAPHITE_INTERVAL
# Get a timestamp for sending to graphite
ts=`date +%s`
# memcache gives us some decent stats in the form of
# STAT bytes_read 4535820
output=`service memcached status 2>/dev/null |
grep STAT |
grep -v version |
sed "s/STAT /memcache\./"`
# Pipe the output through sed, using a regex to
# append a $ts timestamp to the end of each line,
# and then to the correct server and port using netcat
echo "$output" |
sed "s/\$/ $ts/" |
# Echo this data too in case we want to record
# it to a log
echo `date "+%Y-%m-%d_%H:%M:%S"`
echo "$output"
echo; echo
) &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment