#!/usr/bin/env python
#coding: utf8
import sys
import json
import requests
import time
import urllib2, base64
# 获取数据。 如果无法连接fastdfs,也上传0,而不是python报错不处理了。
try:
r = requests.get('http://xx:8090/group1/M00/00/01/CgACJViaiuGAXjWBAAAABmkPdf0105.txt',timeout=3)
if r.text == "ceshi\n":
value = 1
else:
value = 0
except:
value = 0
pass
# 准备上报数据
p = []
endpoint = "10.0.2.90"
metric = "yw"
key = "fastdfsceshi"
timestamp = int(time.time())
step = 60
vtype = "GAUGE"
tags = ''
i = {
'Metric' :'%s.%s'%(metric,key),
'Endpoint': endpoint,
'Timestamp': timestamp,
'Step': step,
'value': value,
'CounterType': vtype,
'TAGS': tags
}
p.append(i)
print json.dumps(p, sort_keys=True,indent = 4)
#sys.exit(0)
# 上报
method = "POST"
handler = urllib2.HTTPHandler()
opener = urllib2.build_opener(handler)
url = "http://127.0.0.1:1988/v1/push"
request = urllib2.Request(url, data=json.dumps(p))
request.add_header('Content-Type','application/json')
request.get_method = lambda: method
try:
connection = opener.open(request)
except urllib2.HTTPError,e:
connection = e
if connection.code == 200:
print connection.read()
else:
print '{"err":1,"msg":"%s"}' % connection
falcon - fastdfs download monitor
最新推荐文章于 2019-05-04 17:33:59 发布