Created
October 26, 2012 15:06
-
-
Save brendanhay/3959309 to your computer and use it in GitHub Desktop.
Random metrics generation for statsd
This file contains 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/bash | |
BUCKETS=(ball sack nut job hax red saw new grunge) | |
TYPES=(g c s ms) | |
usage() { | |
echo "Usage: -h [host] -p [port]" | |
exit 1 | |
} | |
rand() { | |
printf $(($1 * RANDOM / 32767)) | |
} | |
sample() { | |
declare -a ary=("${!1}") | |
unset ary[0] | |
printf $'%s\n' "${ary[$(($(rand "${#ary[*]}")+1))]}" | |
} | |
emit() { | |
local samples rate metric | |
samples=('' "|@0.${RANDOM:0:2}" "") | |
rate=$(sample samples[@]) | |
metric="$(sample BUCKETS[@]):$RANDOM|$(sample TYPES[@])$rate" | |
echo $metric | |
echo $metric | nc -u ${HOST-"127.0.0.1"} ${PORT-"5111"} -c | |
} | |
while getopts ":h:p" opt | |
do | |
case $opt in | |
h) HOST=$OPTARG;; | |
p) PORT=$OPTARG;; | |
*) usage;; | |
esac | |
done | |
while true | |
do | |
emit | |
sleep 0.5 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment