python-eve配置实战
来源:互联网 发布:深圳人工智能企业 编辑:程序博客网 时间:2024/04/30 11:51
我用的是mongoengine
我的document
如下
# hosts表class Hosts(Document): # 从业务库 IP = StringField(unique=True, null=False) az_id = IntField(null=True) meta = { 'collection': 'db_hosts' }# 聚合信息表class AggregateDayHostMetric(Document): # host是ObjectId类型存的是Hosts的_id(mongoengine里是.id来访问) # 括号里的Hosts导致数据库里字段名变为Hosts而不是host host = ObjectIdField('Hosts') # 这里unique_with会自动创建一个联合索引,新加的话要删掉collection重新创建才会生效,这个会引发NotUniqueError BusinessDay = IntField(null=False, unique_with='host') # cpu_metric是指向另一个对象类型在eve可以理解为dict cpu_metric = EmbeddedDocumentField('TypeValue', null=True) meta = { 'collection': 'aggregate_day_host_metric' }
AggregateDayHostMetric = { 'schema': { 'Hosts': { 'type': 'objectid', 'data_relation': { 'resource': 'db_hosts', 'field': '_id', 'embeddable': True } }, 'BusinessDay': { 'type': 'integer' }, 'cpu_metric': { 'type': 'dict' } }}DOMAIN = { 'db_hosts': db_hosts, 'aggregate_day_host_metric': AggregateDayHostMetric}
配置完成,访问: http://host:port/aggregate_day_host_metric?embedded={"Hosts": 1}
即可
# 返回的每个元素结构如下(eve帮你做了查询){ "Hosts": { "SecUsage": "pnat", "IP": "114.114.114.114", "_id": "578dde6f9746ef2cd80f9e70", "Usage": "unet", "az_id": 4001 }, "BusinessDay": 17031, "cpu_metric": { "top_5_avg": 54 }, # 下面是eve自带的暂时用不到,忽略 "_updated": "Thu, 01 Jan 1970 00:00:00 GMT", "_created": "Thu, 01 Jan 1970 00:00:00 GMT", "_id": "57b580739f37e9ac8a10e5ae", "_etag": "8c20ca3037c79f2ad6bea2b1c31af1199651e29e"}
0 0
- python-eve配置实战
- python-eve使用实战
- python eve restful 规则
- python Eve RESTFul 尝试笔记
- python RESTful API框架:Eve 快速入门
- EVE 居然是用 python 写的!!太不可思议了
- python eve设置多数据库问题记录
- 机器学习实战python环境配置
- Christmas Eve
- 12.23 Eve
- Eve Backstory
- web eve
- EVE登录
- eve模拟器
- python爬虫实战——win10 python环境配置
- [Python 实战]
- [Python 实战]
- [Python 实战]
- 色彩的基本概念
- SpringMVC源码阅读系列
- Spring中bean的含义
- 记录下明天的面试
- leetcode 315. Count of Smaller Numbers After Self
- python-eve配置实战
- android 自定义view 水波纹进度球
- shader学习(6)
- 数据结构——线段树(单点更新、)
- 十九、使用PopupWindow
- UVA 10098 Generating Fast
- hdu5867 数学题
- CodeForces 635B Island Puzzle(小岛放雕塑,思维)
- UVA 146 ID Codes