加入收藏 | 设为首页 | 会员中心 | 我要投稿 湖南网 (https://www.hunanwang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 移动互联 > 正文

揭密首个面向IaaS的查询说话:ZStack Query Language(ZQL)

发布时间:2018-08-17 04:05:00 所属栏目:移动互联 来源:ZStack研发团队
导读:技能沙龙 | 邀您于8月25日与国美/AWS/转转三位专家配合切磋小措施电商拭魅战 为了简化UI事变并为运维职员提供一种越发机动的资源查询方法,ZStack在2.6版本中推出了首个面向IaaS的查询说话 ZStack Query Language,简称ZQL。 配景 IaaS打点着海量的数据中心资

在ZStack中行使了两种数据库:相关数据库存放元数据,时序数据库存放监控数据。因为差异数据库查询方法纷歧样,在ZQL之前,用户要查询一个资源的监控数据,必要先通过Query API得到该资源的元数据,再通过ZWatch的查询API得到其监控数据。譬喻要查询一个名为webvm假造机的CPU行使率监控数据,要执行如下API:

QueryVmInstance fields=uuid name=webvm

GetMetricData namespace=ZStack/VM metricName=CPUUsedUtilization labels=VMUuid=QueryVmInstance返回的UUID offsetAheadOfCurrentTime=60

ZQL通过return with子句办理这个题目。return with是一种插件机制,它应承子体系 通过插件将自身的查询前提注入ZQL中,ZQL会先执行相关数据库查询,将满意前提资源的原数据查询出来后,再将资源的主键(primary key)作为输入前提挪用实现return with子句的插件,最后将插件的查询功效一并返回给ZQL的挪用者。

上述查询假造机监控数据的需求可以通过一条ZQL语句实现:

query vminstance.hostUuid,uuid where name = 'webvm' return with (zwatch{resultName='webvm-cpu',metricName='CPUAllUsedUtilization',offsetAheadOfCurrentTime=60})

返回:

{

"results": [

{

"inventories": [

{

"hostUuid": "f8271f58468b4281a212a43e530b5535",

"uuid": "05781209d24341ac84fc055ae71820ac"

}

],

"returnWith": {

"webvm-cpu": [

{

"labels": {

"VMUuid": "05781209d24341ac84fc055ae71820ac"

},

"time": 1533280402,

"value": 0.8

},

{

"labels": {

"VMUuid": "05781209d24341ac84fc055ae71820ac"

},

"time": 1533280462,

"value": 0.8

}

]

}

}

],

"success": true

}

这里我们用一条ZQL语句中即返回了我们感乐趣的元数据字段:uuid和hostUuid,也返回了该假造机的监控数据。仔细的读者已经留意到我们在ZWatch查询字段中指定了参数resultName='webvm-cpu',而且在返回的JSON map中监控数据的key也是webvm-cpu。跟named as要害字一样,这是为了执行多条ZWatch查询子句时利便检索返回功效筹备的。 ZStack UI行使很是伟大的ZQL查询语句,譬喻在TOP 5页面,一条ZQL查询包括多达13个ZWatch查询:

ZQLQuery zql="query vmInstance.uuid,name where zoneUuid='89e148fb667c404dbc5309a2e956fa28' and hypervisorType='KVM' and type='UserVm' and state='Running' return with (zwatch{resultName='CPUAllUsedUtilization',metricName='CPUAllUsedUtilization',offsetAheadOfCurrentTime=60,period=6,functions='average(groupBy="VMUuid")',functions='top(num=5)'},zwatch{resultName='MemoryUsedInPercent',metricName='MemoryUsedInPercent',offsetAheadOfCurrentTime=60,period=6,functions='average(groupBy="VMUuid")',functions='top(num=5)'},zwatch{resultName='MemoryFreeInPercent',metricName='MemoryFreeInPercent',offsetAheadOfCurrentTime=60,period=6,functions='average(groupBy="VMUuid")',functions='top(num=5)'},zwatch{resultName='DiskAllReadOps',metricName='DiskAllReadOps',offsetAheadOfCurrentTime=60,period=6,functions='average(groupBy="VMUuid")',functions='top(num=5)'},zwatch{resultName='DiskAllWriteOps',metricName='DiskAllWriteOps',offsetAheadOfCurrentTime=60,period=6,functions='average(groupBy="VMUuid")',functions='top(num=5)'},zwatch{resultName='DiskAllReadBytes',metricName='DiskAllReadBytes',offsetAheadOfCurrentTime=60,period=6,functions='average(groupBy="VMUuid")',functions='top(num=5)'},zwatch{resultName='DiskAllWriteBytes',metricName='DiskAllWriteBytes',offsetAheadOfCurrentTime=60,period=6,functions='average(groupBy="VMUuid")',functions='top(num=5)'},zwatch{resultName='NetworkOutBytes',metricName='NetworkOutBytes',offsetAheadOfCurrentTime=60,period=6,functions='average(groupBy="VMUuid,NetworkDeviceLetter")',functions='top(num=5)'},zwatch{resultName='NetworkInBytes',metricName='NetworkInBytes',offsetAheadOfCurrentTime=60,period=6,functions='average(groupBy="VMUuid,NetworkDeviceLetter")',functions='top(num=5)'},zwatch{resultName='NetworkOutPackets',metricName='NetworkOutPackets',offsetAheadOfCurrentTime=60,period=6,functions='average(groupBy="VMUuid,NetworkDeviceLetter")',functions='top(num=5)'},zwatch{resultName='NetworkInPackets',metricName='NetworkInPackets',offsetAheadOfCurrentTime=60,period=6,functions='average(groupBy="VMUuid,NetworkDeviceLetter")',functions='top(num=5)'},zwatch{resultName='NetworkOutErrors',metricName='NetworkOutErrors',offsetAheadOfCurrentTime=60,period=6,functions='average(groupBy="VMUuid,NetworkDeviceLetter")',functions='top(num=5)'},zwatch{resultName='NetworkInErrors',metricName='NetworkInErrors',offsetAheadOfCurrentTime=60,period=6,functions='average(groupBy="VMUuid,NetworkDeviceLetter")',functions='top(num=5)'})"

上例是在ZStack CLI中执行时的例子,行使对引号转义

(编辑:湖南网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读