从 falcon api 中获取数据
import json
import time import requests openfalcon = 'http://ip:port/api/v1'
user = 'user'
password = 'password' def get_sig(user=user, password=password):
url = '%s/user/login' % openfalcon
response = requests.post(url, data=dict(name=user, password=password), timeout=2)
return response.json() def get_graph_history(hostname, category, start_time, end_time):
url = '%s/graph/history' % openfalcon
sig = get_sig()
headers = {
'Apitoken': json.dumps({'name': sig['name'], 'sig': sig['sig']}),
'Content-type': 'application/json',
'X-Forwarded-For': '127.0.0.1',
} counters = [
"cpu.idle",
"cpu.iowait",
"cpu.user",
"cpu.system",
"cpu.iowait",
"cpu.irq",
"cpu.softirq",
"mem.memfree.percent",
"mem.swapfree.percent",
"df.bytes.free.percent/fstype=ext4,mount=/",
"df.bytes.free.percent/fstype=ext4,mount=/data",
"net.if.in.bytes/iface=eth0",
"net.if.out.bytes/iface=eth0",
"net.if.in.packets/iface=eth0",
"net.if.out.packets/iface=eth0",
"net.if.in.dropped/iface=eth0",
"net.if.out.dropped/iface=eth0",
"net.if.in.errors/iface=eth0",
"net.if.out.errors/iface=eth0",
"ss.estab",
"load.1min",
"load.5min",
"load.15min",
"disk.io.read_bytes/device=vda",
"disk.io.read_bytes/device=vdb",
"disk.io.write_bytes/device=vda",
"disk.io.write_bytes/device=vdb",
"disk.io.msec_total/device=vda",
"disk.io.msec_total/device=vdb",
"disk.io.avgrq_sz/device=vdb",
"disk.io.avgqu-sz/device=vdb",
"disk.io.await/device=vdb",
"disk.io.svctm/device=vdb",
"disk.io.util/device=vdb",
] if 'cpu' == category:
counters = counters[0:7]
elif 'memory' == category:
counters = counters[7:9]
elif 'disk' == category:
counters = counters[9:11]
elif 'net' == category:
counters = counters[11:20]
elif 'io' == category:
counters = counters[20:23]
else:
counters = counters[23:] data = {
"step": 60,
"start_time": start_time,
"hostnames": [hostname],
"end_time": end_time,
"counters": counters,
"consol_fun": "AVERAGE"
}
response = requests.post(url, headers=headers, data=json.dumps(data))
return response.json() if __name__ == '__main__':
end_time = int(time.time())
start_time = end_time - 300
print get_graph_history('host-001', 'io', start_time, end_time)
从 falcon api 中获取数据的更多相关文章
- requests从api中获取数据并存放到mysql中
python的requests库是一个非常强大的库,requests的安装方法十分简单,用: pip install requests 即可安装requests,安装成功后: import reque ...
- 从api接口获取数据-okhttp
首先先介绍下api接口: API:应用程序接口(API:Application Program Interface) 通常用于数据连接,调用函数提供功能等等... 从api接口获取数据有四种方式:Ht ...
- Thymeleaf+SpringMVC,如何从模板中获取数据
Thymeleaf+SpringMVC,如何从模板中获取数据 在一个典型的SpringMVC应用中,带@Controller注解的类负责准备数据模型Map的数据和选择一个视图进行渲染.这个模型Map对 ...
- hive从查询中获取数据插入到表或动态分区
Hive的insert语句能够从查询语句中获取数据,并同时将数据Load到目标表中.现在假定有一个已有数据的表staged_employees(雇员信息全量表),所属国家cnty和所属州st是该表的两 ...
- 哪种方式更适合在React中获取数据?
作者:Dmitri Pavlutin 译者:小维FE 原文:dmitripavlutin.com 国外文章,笔者采用意译的方式,以保证文章的可读性. 当执行像数据获取这样的I/O操作时,你必须发起获取 ...
- Django Form 实时从数据库中获取数据
修改 models.py 添加 class UserType(models.Model): caption = models.CharField(max_length=32) 执行命令,生成数据库 p ...
- SpringMVC从Request域中获取数据
SpringMVC从Request域中获取数据的三种方式 SpringMVC环境自行搭建, 约定存在如下目录和文件:/WEB-INF/pages/success.jsp 方式一:传入Model对象 前 ...
- SQL语句的使用,SELECT - 从数据库表中获取数据 UPDATE - 更新数据库表中的数据 DELETE - 从数据库表中删除数据 INSERT INTO - 向数据库表中插入数据
SQL DML 和 DDL 可以把 SQL 分为两个部分:数据操作语言 (DML) 和 数据定义语言 (DDL). SQL (结构化查询语言)是用于执行查询的语法. 但是 SQL 语言也包含用于更新. ...
- Vue3 组合式 API 中获取 DOM 节点的问题
模板引用 Vue 提供了许多指令让我们可以直接操作组件的模板.但是在某些情况下,我们仍然需要访问底层 DOM 元素.在模板中添加一个特殊的属性ref就可以得到该元素. 访问模板引用 <scrip ...
随机推荐
- [SoapUI] 将科学计数法转化为普通数字,并且只保留小数点后几位
方案一: import java.text.NumberFormat class CompareHashMap { def regEx_Numeric = '-?[1-9]\\d*$|-?([1-9] ...
- dateframe取数据
import numpy as npimport pandas as pd## x1=[1,2,3,4]# x2=[4,5,6,7]# x3=[7,8,9,10]# df=pd.DataFrame(# ...
- 社交类APP原型模板分享——Tinder
Tinder是国外的一款手机交友APP,作用是基于用户的地理位置,每天“推荐”一定距离内的四个对象,根据用户在 Facebook 上面的共同好友数量.共同兴趣和关系网给出评分,得分最高的推荐对象优先展 ...
- 【Mac】使用QuickTime Player录制屏幕录像
我门分享都需要用到录屏软件,Mac系统有自带的QuickTime Player软件可以录制屏幕录像 环境与工具 1.mac系统 2.mac自带的QuickTime Player软件 使用方法 1.打开 ...
- android触控,先了解MotionEvent(一)
http://my.oschina.net/banxi/blog/56421 这是我个人的看法,要学好android触控,了解MotionEvent是必要,对所用的MotionEvent常用的API要 ...
- 2018.09.10 bzoj1855: [Scoi2010]股票交易(单调队列优化dp)
传送门 单调队列优化dp好题. 有一个很明显的状态设置是f[i][j]表示前i天完剩下了j分股票的最优值. 显然f[i][j]可以从f[i-w-1][k]转移过来. 方程很好推啊. 对于j<kj ...
- returning into 语句
returning into 语句用于执行完语句后返回的值,具体返回执行之前或者之后的结果,多用于在存储过程中 如下所述:delete语句的returning into语句返回的是delete之前的结 ...
- OPCache使用示例
OPcache 有什么用? OPcache 通过将 PHP 脚本预编译的字节码存储到共享内存中来提升 PHP 的性能, 存储预编译字节码的好处就是 省去了每次加载和解析 PHP 脚本的开销. OPca ...
- Hdu3363 Ice-sugar Gourd 2017-01-16 11:39 43人阅读 评论(0) 收藏
Ice-sugar Gourd Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- What if you are involved in an automobile accident in the US
What if you are involved in an automobile accident in the US With increasing Chinese tourists and vi ...