open-falcon api相关
2024-08-30 04:40:45
本文描述通过被监控endpoint的名称获取该endpoint的eid和监控项,从而获取到该endpoint的监控历史数据,使用python代码的 api操作方法
注:同步open-falcon和agent的时间,不然获取不到数据
http://open-falcon.org/falcon-plus/#/endpoints
访问的api有:
/api/v1/graph/endpoint?q={0}
/api/v1/graph/endpoint_counter?eid={0}
/api/v1/graph/history
具体操作:
# -*- coding: UTF-8 -*-
#!/usr/bin/env python
# Created by Administrator on 2017/12/15
import json
import time
import requests in_ip = 'localhost.localdomain'
user = 'root'
sig = '78d70632d20311e7bf7d000c298269bc' # 注:sig为数据库uic表中用户对应的sig
domain = 'http://192.168.67.129:8080' # api对应端口为8080
api_token = '{"name":"' + user + '", "sig":"' + sig + '"}'
directiry = "/api/v1/graph/endpoint?q={0}".format(in_ip) falcon_header = {
"Apitoken": api_token,
"X-Forwarded-For": "127.0.0.1",
"Content-Type": "application/json",
"name": user,
"sig": sig
} params = {
'url': domain + directiry,
'headers': falcon_header,
'timeout': 30
}
res1 = requests.get(**params)
data1 = json.loads(res1.text)
print('得到eid',data1)
#=========================================================================
point_id = data1[0]["id"]
directiry="/api/v1/graph/endpoint_counter?eid={0}".format(point_id)
params = {
'url': domain + directiry,
'headers': falcon_header,
'timeout': 30
}
res2 = requests.get(**params)
data2 = json.loads(res2.text)
print('得到具体监控项',data2)
#=========================================================================
counters = [ counter["counter"] for counter in data2 ] end_time = int(time.time()) # 必须要整形
start_time = end_time - 1800 # 30分钟
directiry="/api/v1/graph/history"
params = {
'url': domain + directiry,
'headers': falcon_header,
'timeout': 30
} payload = {
"step": 60,
"start_time": start_time,
"hostnames": [in_ip, ],
"end_time": end_time,
"counters": counters,
"consol_fun": "AVERAGE"
}
params['data'] = json.dumps(payload) res3 = requests.post(**params)
data3 = json.loads(res3.text)
# print('得到指定监控项的历史记录',data3) data = dict([(iter["counter"], iter["Values"]) for iter in data3]) #===============格式化数据==========================================
for key in data:
values = data[key]
data[key] = [{"timestamp": time.strftime('%H:%M', time.localtime(k["timestamp"])), "value": k["value"]} for k in
values if k["value"]] data["in_ip"] = in_ip print('得到指定监控项的历史记录',data)
最新文章
- mssql2000 身份证号码验证
- TextBox禁止复制粘贴和数字验证,小数验证,汉字验证
- link cut tree 入门
- C++中变量自动初始化的问题
- sencha touch2 动画问题
- python----slots属性安全类
- JVM学习②
- 学习笔记1--响应式网页+Bootstrap起步+全局CSS样式
- vue打包上传oss
- c/c++ 有向无环图 directed acycline graph
- BZOJ4124 : [Baltic2015]Tug of war
- Nginx 限制访问速率
- Socket阻塞模式和非阻塞模式的区别
- auto关键字使用
- BZOJ2734 HNOI2012集合选数(状压dp)
- JedisCluster中应用的Apache Commons Pool对象池技术
- MySQL(四)执行计划
- Python atan() 函数
- Halcon 笔记2 Blob分析
- mac下安装伪分布hadoop2.6.0和hbase1.0.1.1