Skip to content

Instantly share code, notes, and snippets.

@benmmurphy
Created November 13, 2012 09:48
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save benmmurphy/4064937 to your computer and use it in GitHub Desktop.
Save benmmurphy/4064937 to your computer and use it in GitHub Desktop.
riak -> librato stats cron job
#!/bin/bash
# * * * * * root /path/to/riak_stats.sh
set -e
SOURCE=$(hostname)
LIBRATO_USERID=""
LIBRATO_TOKEN=""
PREFIX="test.riak"
STATUS=$(riak-admin status)
VARIABLES=("vnode_gets" "vnode_puts" "read_repairs" "node_gets" "node_puts" "cpu_nprocs" "sys_process_count" "pbc_connects" "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")
IDX=0
PARAMS=()
for STAT in ${VARIABLES[@]}; do
RE_PREFIX=$'(\n|^)'
RE_SUFFIX=$' : ([^\n]*)'
RE="$RE_PREFIX$STAT$RE_SUFFIX"
if [[ "$STATUS" =~ $RE ]]; then
VALUE=${BASH_REMATCH[2]}
PARAMS+=("-d" "gauges[$IDX][name]=$PREFIX.$STAT")
PARAMS+=("-d" "gauges[$IDX][value]=$VALUE")
PARAMS+=("-d" "gauges[$IDX][source]=$SOURCE")
IDX=$(($IDX + 1))
fi
done
curl -v --max-time 15 \
-u ${LIBRATO_USERID}:${LIBRATO_TOKEN} \
${PARAMS[@]} \
-X POST https://metrics-api.librato.com/v1/metrics
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment