Skip to content

Instantly share code, notes, and snippets.

@benmmurphy
Last active October 12, 2015 17:57
Show Gist options
  • Save benmmurphy/4064990 to your computer and use it in GitHub Desktop.
Save benmmurphy/4064990 to your computer and use it in GitHub Desktop.
riak -> graphite stats cron job
#!/bin/bash
# * * * * * root /path/to/riak_graphite_stats.sh
set -e
SOURCE=$(hostname)
GRAPHITE_PORT=2003
GRAPHITE_SERVER="server"
PREFIX="riak_stats"
STATUS=$(/usr/sbin/riak-admin status)
VARIABLES=("cpu_nprocs" "sys_process_count" "pbc_active" \
"node_get_fsm_time_mean" "node_get_fsm_time_median" "node_get_fsm_time_95" "node_get_fsm_time_99" "node_get_fsm_time_100" \
"node_put_fsm_time_mean" "node_put_fsm_time_median" "node_put_fsm_time_95" "node_put_fsm_time_99" "node_put_fsm_time_100")
COUNT_VARIABLES=("vnode_gets" "vnode_puts" "read_repairs" "node_gets" "node_puts" "pbc_connects")
DATE=$(date +%s)
function write_stat() {
local STAT=$1
local SUFFIX=$2
RE_PREFIX=$'(\n|^)'
RE_SUFFIX=$' : ([^\n]*)'
RE="$RE_PREFIX$STAT$RE_SUFFIX"
if [[ "$STATUS" =~ $RE ]]; then
VALUE=${BASH_REMATCH[2]}
echo "$PREFIX.$SOURCE.$STAT$SUFFIX $VALUE $DATE" | nc ${GRAPHITE_SERVER} ${GRAPHITE_PORT}
fi
}
for STAT in ${VARIABLES[@]}; do
write_stat $STAT ""
done
for STAT in ${COUNT_VARIABLES[@]}; do
write_stat $STAT ".count"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment