Created
August 6, 2016 21:22
-
-
Save kebre001/f381a2cf63907acfb869099031544f43 to your computer and use it in GitHub Desktop.
Python script to replace cachet-monitor
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
import os | |
import subprocess | |
import httplib, urllib | |
import json | |
proc = subprocess.Popen(['curl -w %{time_total}\\n -o /dev/null -s "http://WEBSITE_TO_MONITOR/"'], | |
stdout=subprocess.PIPE, shell=True) | |
(out, err) = proc.communicate() | |
out = out.rstrip('n') | |
out = float(out) * int(1000) | |
out = int(out) | |
#print("MS: %s" % (out)) | |
params = '{"id": 1, "value": %s}' % (out) | |
headers = {"Content-Type": "application/json", "X-Cachet-Token": "CACHET_API_TOKEN"} | |
conn = httplib.HTTPConnection("CACHET_URL:80") | |
conn.request("POST", "/api/v1/metrics/CACHET_METRIC_ID/points", params, headers) | |
response = conn.getresponse() | |
#print("Response: %s, %s" % (response.status, response.reason)) | |
conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment