背景:falcon设置自己想要的监控,指定metric
过程:
#!/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)
总结:falcon-agent对client的监控取值,是按照固定的格式走的,理论来说,只要agent通过v1/push 1988端口传给transfer的值符合固定的格式,即可监控任何指标