1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
#!/bin/bash -e
trap 'kill $(jobs -p)' EXIT
installed() {
which $1 > /dev/null
}
log() {
echo >&2 $1
}
fatal() {
log $1
exit 1
}
if ! installed vegeta; then
if ! installed go; then
fatal "Could not find go. Either run the examples manually or install"
fi
go get github.com/tsenart/vegeta
go install github.com/tsenart/vegeta
fi
PORT=5000
URL=http://127.0.0.1:${PORT}/
log "starting example server"
bundle install --quiet
bundle exec unicorn -p ${PORT} -c unicorn.conf &>> /dev/null &
# wait until unicorn is available
sleep 1
log "sending requests for 5 seconds"
printf "GET ${URL}\nPOST ${URL}\nDELETE ${URL}" | vegeta attack -duration 5s &>> /dev/null
log "printing /metrics"
curl -s "${URL}metrics"
|