Last active
August 29, 2015 14:00
-
-
Save niwo/16e5977e1df27f82c975 to your computer and use it in GitHub Desktop.
Send page load time to librato
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/bash | |
: ${LIBRATO_EMAIL:?"Need to set LIBRATO_EMAIL"} | |
: ${LIBRATO_TOKEN:?"Need to set LIBRATO_TOKEN"} | |
LIBRATO_CREDS="$LIBRATO_EMAIL:$LIBRATO_TOKEN" | |
LIBRATO_URL="https://metrics-api.librato.com/v1/metrics" | |
PAGE=$1 | |
SENSOR=${2:-$HOSTNAME} | |
if [[ $# -lt 1 ]] ; then | |
echo 'Usage: page_load_to_librato.sh <URL> [sensor-name]' | |
exit 0 | |
fi | |
page_load=`echo $(curl -s -w "%{time_total}:%{speed_download}\n" -o /dev/null $PAGE | sed 's/,/\./g')` | |
time=`echo $page_load | awk -F':' '{print $1}'` | |
speed=`echo $page_load | awk -F':' '{print $2}'` | |
data='&gauges[0][name]=LOAD_TIME' | |
data+='&gauges[0][value]='$time'' | |
data+='&gauges[0][source]='$SENSOR'' | |
data+='&gauges[1][name]=DOWNLOAD_SPEED' | |
data+='&gauges[1][value]='$speed'' | |
data+='&gauges[1][source]='$SENSOR'' | |
curl -s -u $LIBRATO_CREDS -X POST $LIBRATO_URL --data $data |
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
LIBRATO_EMAIL="[email protected]" | |
LIBRATO_TOKEN="7376sdgdjhwsd8w7d7as687a8d8sa7d97a989a8s8d68a7s87d9797aq9" | |
* * * * * /opt/page_load_to_librato.sh http://www.google.com/ amsterdam-1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment