#!/usr/bin/python
#coding=utf-8
import requests,simplejson
import time,datetime
import socket
hostname = socket.gethostname()
#print hostname
timestamp = int(time.time())
try:
req = requests.get(‘http://127.0.0.1:80/api/check/checktime’)
res_dict = simplejson.loads(req.text)
status = res_dict[‘code’]
except Exception as e:
if e:
status = 1
payload = [
{
“endpoint”:hostname,
“metric”:“php-status”,
“timestamp”:timestamp,
“step”:60,
“value”: status,
“counterType”:“GAUGE”,
“tags”:""
}
]
uri = “http://127.0.0.1:1988/v1/push”
requests.post(uri,json=payload)
相关文章: