Last active
August 29, 2015 14:05
-
-
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
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
#!/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