最近發現AWS某區的服務器重啟了,而且重啟后,程序起不來也就算了,發現防火墻也打開了,果斷處理
iptables -t filter -Fchkconfig iptables off之后,需要添加針對fastdfs的監控,當然,還是采用openfalcon即可。
腳本如下:
#!/usr/bin/env python#coding: utf8import sysimport jsonimport requestsimport timeimport urllib2, base64# 獲取數據r = requests.get('http://xxx/group1/M00/00/01/CgACJViaiuGAXjWBAAAABmkPdf0105.txt')if r.text == "ceshi/n": value = "1"else: value = "0"# 準備上報數據p = []endpoint = "10.0.2.90"metric = "yw"key = "fastdfsceshi"timestamp = int(time.time())step = 60vtype = "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: methodtry: connection = opener.open(request)except urllib2.HTTPError,e: connection = eif connection.code == 200: print connection.read()else: print '{"err":1,"msg":"%s"}' % connection當然,ceshi.txt文件還是要先上傳到fastdfs里面的
fdfs_upload_file ~/fastdfs/etc/fdfs/client.conf ceshi.txt定時任務* * * * * cd /data/openfalcon/open-falcon/agent/userdefine && ./yw.fastdfsceshi然后就可以添加報警了看看圖形畫的咋樣來
新聞熱點
疑難解答