本文描述通过被监控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)

最新文章

  1. mssql2000 身份证号码验证
  2. TextBox禁止复制粘贴和数字验证,小数验证,汉字验证
  3. link cut tree 入门
  4. C++中变量自动初始化的问题
  5. sencha touch2 动画问题
  6. python----slots属性安全类
  7. JVM学习②
  8. 学习笔记1--响应式网页+Bootstrap起步+全局CSS样式
  9. vue打包上传oss
  10. c/c++ 有向无环图 directed acycline graph
  11. BZOJ4124 : [Baltic2015]Tug of war
  12. Nginx 限制访问速率
  13. Socket阻塞模式和非阻塞模式的区别
  14. auto关键字使用
  15. BZOJ2734 HNOI2012集合选数(状压dp)
  16. JedisCluster中应用的Apache Commons Pool对象池技术
  17. MySQL(四)执行计划
  18. Python atan() 函数
  19. Halcon 笔记2 Blob分析
  20. mac下安装伪分布hadoop2.6.0和hbase1.0.1.1

热门文章

  1. oracle中的内连接和外连接区别
  2. Android 实现动态匹配输入的内容 AutoCompleteTextView和MultiAutoCompleteTextView
  3. JAVA中替换字符的方法replace和replaceAll 区别
  4. 学习JQuery - 10
  5. C++虚继承的概念[转]
  6. 有关InitialContext()的困惑 <转>
  7. linux常用的一些访问目录
  8. SNMP信息泄露漏洞
  9. android通过数组,流播放声音的方法,音频实时传输
  10. vue-cli 项目打包异常汇总