获取metric数据(GetMetricData)

GetMetricData用于获得metric的数据:
GetMetricData namespace=ZStack/Host metricName=NetworkAllOutBytes

参数(Parameters)

名字 描述 可选的 可选的参数值 起始支持版本
namespace 名字空间 2.3
metricName 监控项 2.3
startTime 起始时间 2.3
endTime 结束时间 2.3
period 数据精度 2.3
labels 过滤标签 2.3
functions 函数列表 2.3
offsetAheadOfCurrentTime 2.3
userTags 用户标签,请参见 创建用户标签(CreateUserTag) 2.3
systemTags 系统标签,请参见 创建系统标签(CreateSystemTag) 2.3
timeout
返回metric的时序数据:
{
    "data": [
        {
            "labels": {
                "HostUuid": "a133cbcfdc1d462c9b51d7bce6ac6b11"
            },
            "time": 1516363957,
            "value": 1678.9
        },
        {
            "labels": {
                "HostUuid": "a133cbcfdc1d462c9b51d7bce6ac6b11"
            },
            "time": 1516364017,
            "value": 1920.1000000000001
        }
    ],
    "success": true
}
  • 其中value为double型的数据值,time是epoch time(单位秒),labels为标签组,可以用于过滤返回值。例如只获取UUID为a133cbcfdc1d462c9b51d7bce6ac6b11物理机的数据:
    GetMetricData namespace=ZStack/Host metricName=NetworkAllOutByte labels=HostUuid=a133cbcfdc1d462c9b51d7bce6ac6b11
  • 标签支持=(等于)和=~正则两种匹配方式,可以用正则匹配多个标签值。例如返回UUID为a133cbcfdc1d462c9b51d7bce6ac6b11506bd3b46a6543718488b5ba5850aaaa两个物理机的metric值,可以用:
    GetMetricData namespace=ZStack/Host metricName=NetworkAllOutByte labels=HostUuid=~a133cbcfdc1d462c9b51d7bce6ac6b11|506bd3b46a6543718488b5ba5850aaaa
  • 可以传入多个标签作为过滤条件,例如:
    GetMetricData namespace=ZStack/PrimaryStorage metricName=SnapshotCount labels=PrimaryStorageUuid=b632652cc16044cdb6b4f516ed93a118,PrimaryStorageType=Ceph
  • 可以通过startTimeendTime指定查询的时间范围:
    GetMetricData namespace=ZStack/PrimaryStorage metricName=SnapshotCount labels=PrimaryStorageUuid=b632652cc16044cdb6b4f516ed93a118,PrimaryStorageType=Ceph startTime=1516364017 endTime=1516365000
    Note: startTime/endTime均为epoch time。若都省略,默认返回最近1分钟内的数据。若endTime省略,则其值默认为当前时间。
  • period用于指定返回数据的时间精度 TODO
  • 可以通过functions传入一组函数对数据进行后处理,例如:
    GetMetricData namespace=ZStack/PrimaryStorage metricName=SnapshotCount labels=PrimaryStorageUuid=b632652cc16044cdb6b4f516ed93a118,PrimaryStorageType=Ceph startTime=1516364017 endTime=1516365000 functions=sort(by=\"value\"\\,direction=\"desc\")
  • 这里使用sort函数对返回结果的value进行降序排序。传入多个函数时按顺序执行,例如:
    GetMetricData namespace=ZStack/PrimaryStorage metricName=SnapshotCount labels=PrimaryStorageUuid=b632652cc16044cdb6b4f516ed93a118,PrimaryStorageType=Ceph startTime=1516364017 endTime=1516365000 functions=sort(by=\"value\"\\,direction=\"desc\"),limit(limit=1)
    Note: 在CLI中需要对函数中的"\转移,用于分隔函数参数的,需要用\\转译
  • 先对数据排序,然后返回第一个数据。
    Note: 函数具体支持列表见附录