Created
October 8, 2014 16:15
-
-
Save thraxil/a362d7cdef62660b131c to your computer and use it in GitHub Desktop.
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
import requests | |
from socket import socket | |
import time | |
URLS = [("wiki.", "http://wiki.ccnmtl.columbia.edu/"), | |
("jtsa.", "http://learn.jtsa.edu/"), | |
("polarhub.", "http://thepolarhub.org/"), | |
("edblogs.", "http://edblogs.columbia.edu/"), | |
] | |
CARBON_HOST = "nanny.cul.columbia.edu" | |
CARBON_PORT = 2003 | |
PREFIX = "ccnmtl.app.gauges.watcher" | |
for (identifier, URL) in URLS: | |
r = requests.get(URL) | |
delta = int(1000. * r.elapsed.total_seconds()) | |
now = int(time.time()) | |
message = """%s.%sstatus_code %d %d | |
%s.%stime %d %d | |
%s.%schars %d %d | |
""" % (PREFIX, identifier, r.status_code, now, | |
PREFIX, identifier, delta, now, | |
PREFIX, identifier, len(r.text), now) | |
print message | |
sock = socket() | |
try: | |
sock.connect((CARBON_HOST, CARBON_PORT)) | |
except: | |
print "couldn't send metrics to carbon" | |
sys.exit(1) | |
sock.sendall(message) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment