Skip to content

Instantly share code, notes, and snippets.

@briceburg
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save briceburg/952e2fd7e1d67d7604f9 to your computer and use it in GitHub Desktop.
Save briceburg/952e2fd7e1d67d7604f9 to your computer and use it in GitHub Desktop.
reporting pageload times to librato with python ; useful for monitoring responsiveness and triggering error situations via thresholds
#!/apps/pageloadtimes/venv/bin/python
#
# librato-pageloadtimes.py
# / Brice Burgess @iceburg_net
#
# Reports the load time (in milliseconds) of URLs from url_list
# as a metric named "pageloadtimes.<hostname>" to librato.
#
# For easy instrumentation, the URL is reported as the metric's "source"
#
# If a http response code <> 200 is encountered, it will report 9999
# as a magical way to indicate failure.
#
import librato
import requests
import socket
url_list = ["www.google.com","www.iceburg.net"]
librato_api = librato.connect('librato@email', 'librato_token')
librato_queue = librato_api.new_queue()
librato_metric_name = 'pageloadtimes.' + socket.gethostname()
for url in url_list:
request = requests.get('http://' + url + '/')
loadtime = int(request.elapsed.total_seconds() * 1000)
if request.status_code != 200:
loadtime = 9999
librato_queue.add(librato_metric_name, loadtime, source=url)
librato_queue.submit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment