python 监控elasticsearch集群状态并推送到openfalcon
#!/usr/bin/python#! --*-- coding:utf-8 --*--
import requests
import time
import json
import sys
import commands
ts = int(time.time())
#print ts
cmd = 'curl 172.31.0.92:9200/_cat/health'
(a, b) = commands.getstatusoutput(cmd)
#print b
status= b.split(' ')
if status=='green':
healthy=3
elif status=='yellow':
healthy=2
elif status=='red':
healthy=1
else:
healthy=0
#print healthy
payload = [
{
"endpoint": "TBK01",
"metric": "elasticsearch_status",
"timestamp": ts,
"step": 60,
"value": 1,
"counterType": "GAUGE",
"tags": "status=green",
}
]
r = requests.post("http://127.0.0.1:1988/v1/push", data=json.dumps(payload))
#print r.text
页:
[1]