Created
June 3, 2013 20:59
-
-
Save netshade/5701377 to your computer and use it in GitHub Desktop.
Collect a bunch of command outputs in a shell script and send to Instrumental, no dependencies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [ -z "$1" ] | |
then | |
echo "You have to pass your Instrumental API token as an argument to this script." | |
exit -1 | |
fi | |
instrumental_token=$1 | |
# List of keys and commands to run for them | |
declare -a measurements=( | |
# KEY # COMMAND | |
"size_of_foo_list" 'redis-cli --raw llen foolist' | |
"just_the_number_5" 'echo 5' | |
) | |
map_size=`expr ${#measurements[@]} - 1` | |
# Instrumental outgoing packet | |
hello="hello version 1.0\n" | |
authenticate="authenticate ${instrumental_token}\n" | |
packet=$hello$authenticate | |
for idx in `seq 0 2 ${map_size}` | |
do | |
key=${measurements[$idx]} | |
cmd=${measurements[`expr ${idx} + 1`]} | |
result=`${cmd}` | |
rc=$? | |
if [[ $rc != 0 ]] | |
then | |
echo "Failed to exec" $cmd | |
exit $rc | |
fi | |
packet="${packet}gauge ${key} ${result}\n" | |
done | |
if [[ -n "$DEBUG" ]] | |
then | |
echo $packet | |
fi | |
echo $packet | nc collector.instrumentalapp.com 8000 |
I should note that this sort of script would likely be executed via a cron job
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should be noted that the command outputs should be numbers and nothing else