Skip to content

Instantly share code, notes, and snippets.

@netshade
Created June 3, 2013 20:59
Show Gist options
  • Save netshade/5701377 to your computer and use it in GitHub Desktop.
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
#!/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
@netshade
Copy link
Author

netshade commented Jun 3, 2013

Should be noted that the command outputs should be numbers and nothing else

@netshade
Copy link
Author

netshade commented Jun 3, 2013

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