时序数据(Metric)

获取所有metric元数据(GetAllMetricMetadata)

API请求

URLs
GET zstack/v1/zwatch/metrics/meta-data
Headers
Authorization: OAuth the-session-uuid
Curl示例
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X GET http://localhost:8080/zstack/v1/zwatch/metrics/meta-data?name=VMHAProcess
参数列表
名字 类型 位置 描述 可选值 起始版本
name (可选) String query 监控指标名称 3.9.0
namespace (可选) String query 监控指标命名空间 3.9.0
systemTags (可选) List query 系统标签 2.3
userTags (可选) List query 用户标签 2.3

API返回

返回示例
{
  "metrics": [
    {
      "namespace": "ZStack/VM",
      "name": "org.zstack.zwatch.datatype.Metric@4efa6b58",
      "description": "CPUIdleUtilization",
      "labelNames": [
        "VMUuid",
        "CPUNum"
      ],
      "driver": "PrometheusDatabaseDriver"
    }
  ]
}
名字 类型 描述 起始版本
error ErrorCode 错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error 2.3
metrics List 详情参考metrics 2.3
#error
名字 类型 描述 起始版本
code String 错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001 0.6
description String 错误的概要描述 0.6
details String 错误的详细信息 0.6
elaboration String 保留字段,默认为null 0.6
opaque LinkedHashMap 保留字段,默认为null 0.6
cause ErrorCode 根错误,引发当前错误的源错误,若无原错误,该字段为null 0.6
#metrics
名字 类型 描述 起始版本
namespace String 名字空间 2.3
name String 资源名称 2.3
description String 描述 3.9.0
labelNames List 标签名 2.3

SDK示例

Java SDK
GetAllMetricMetadataAction action = new GetAllMetricMetadataAction();
action.name = "VMHAProcess";
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
GetAllMetricMetadataAction.Result res = action.call();
Python SDK
GetAllMetricMetadataAction action = GetAllMetricMetadataAction()
action.name = "VMHAProcess"
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
GetAllMetricMetadataAction.Result res = action.call()

获取metric数据(GetMetricData)

API请求

URLs
GET zstack/v1/zwatch/metrics
Headers
Authorization: OAuth the-session-uuid
Curl示例
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X GET http://localhost:8080/zstack/v1/zwatch/metrics?namespace=ZStack/VM&metricName=CPUIdleUtilization&startTime=
1.588831825415E12&period=30.0&labels=VMUuid=b89391d8b93b470a99055001a4383cc7&labels=CPUNum=4
参数列表
名字 类型 位置 描述 可选值 起始版本
namespace String query 名字空间 2.3
metricName String query 监控项 2.3
startTime (可选) Long query 起始时间 2.3
endTime (可选) Long query 结束时间 2.3
period (可选) Integer query 数据精度 2.3
labels (可选) List query 过滤标签 2.3
systemTags (可选) List query 系统标签 2.3
userTags (可选) List query 用户标签 2.3
functions (可选) List query 函数列表 2.3
offsetAheadOfCurrentTime (可选) Long query 2.3

API返回

返回示例
{
  "data": [
    {
      "value": 101.02,
      "time": 1.519829245957E12,
      "labels": {
        "VMUuid": "9304ab73d9b84852ad1d5061fd4760a5"
      }
    }
  ]
}
名字 类型 描述 起始版本
error ErrorCode 错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error 2.3
data List 详情参考data 2.3
#error
名字 类型 描述 起始版本
code String 错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001 0.6
description String 错误的概要描述 0.6
details String 错误的详细信息 0.6
elaboration String 保留字段,默认为null 0.6
opaque LinkedHashMap 保留字段,默认为null 0.6
cause ErrorCode 根错误,引发当前错误的源错误,若无原错误,该字段为null 0.6
#data
名字 类型 描述 起始版本
value double 监控值 0.6
time long 记录生成时间 0.6
labels Map 标签 0.6

SDK示例

Java SDK
GetMetricDataAction action = new GetMetricDataAction();
action.namespace = "ZStack/VM";
action.metricName = "CPUIdleUtilization";
action.startTime = 1.519829246005E12;
action.period = 30.0;
action.labels = asList("VMUuid=3bb5b754320a4331bd907f10d8683568","CPUNum=4");
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
GetMetricDataAction.Result res = action.call();
Python SDK
GetMetricDataAction action = GetMetricDataAction()
action.namespace = "ZStack/VM"
action.metricName = "CPUIdleUtilization"
action.startTime = 1.519829246005E12
action.period = 30.0
action.labels = [VMUuid=b577cfe6aad447c1b2e793fdc6d7975b, CPUNum=4]
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
GetMetricDataAction.Result res = action.call()

获取metric的标签值(GetMetricLabelValue)

API请求

URLs
GET zstack/v1/zwatch/metrics/label-values
Headers
Authorization: OAuth the-session-uuid
Curl示例
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X GET http://localhost:8080/zstack/v1/zwatch/metrics/label-values?namespace=ZStack/VM&metricName=CPUIdleUtilization&startTime=1.58806818E9&endTime=1.58806824E9&labelNames=CPUNum&filterLabels=VMUuid=e47f7145f4cd4fca8e2856038ecdf3e1
参数列表
名字 类型 位置 描述 可选值 起始版本
namespace String query 名字空间名称 2.3
metricName String query 监控指标名称 2.3
labelNames List query 要获取值得标签名列表 2.3
filterLabels (可选) List query 标签过滤器列表,例如可以指定标签HostUuid=e47f7145f4cd4fca8e2856038ecdf3e1来选择特定主机的,labelNames中指定标签的值 2.3
startTime (可选) Long query 起始时间 3.9.0
endTime (可选) Long query 结束时间 3.9.0
systemTags (可选) List query 系统标签 2.3
userTags (可选) List query 用户标签 2.3

API返回

返回示例
{
  "labels": [
    {
      "VMUuid": "e47f7145f4cd4fca8e2856038ecdf3e1",
      "CPUNum": "1"
    }
  ]
}
名字 类型 描述 起始版本
labels List 标签值 0.6
error ErrorCode 错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error 0.6
#error
名字 类型 描述 起始版本
code String 错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001 0.6
description String 错误的概要描述 0.6
details String 错误的详细信息 0.6
elaboration String 保留字段,默认为null 0.6
opaque LinkedHashMap 保留字段,默认为null 0.6
cause ErrorCode 根错误,引发当前错误的源错误,若无原错误,该字段为null 0.6

SDK示例

Java SDK
GetMetricLabelValueAction action = new GetMetricLabelValueAction();
action.namespace = "ZStack/VM";
action.metricName = "CPUIdleUtilization";
action.startTime = 1.58806818E9;
action.endTime = 1.58806824E9;
action.labelNames = asList("CPUNum");
action.filterLabels = asList("VMUuid=e47f7145f4cd4fca8e2856038ecdf3e1");
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
GetMetricLabelValueAction.Result res = action.call();
Python SDK
GetMetricLabelValueAction action = GetMetricLabelValueAction()
action.namespace = "ZStack/VM"
action.metricName = "CPUIdleUtilization"
action.startTime = 1.58806818E9
action.endTime = 1.58806824E9
action.labelNames = [CPUNum]
action.filterLabels = [VMUuid=e47f7145f4cd4fca8e2856038ecdf3e1]
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
GetMetricLabelValueAction.Result res = action.call()

存入自定义metric数据(PutMetricData)

API请求

URLs
POST zstack/v1/zwatch/metrics
Headers
Authorization: OAuth the-session-uuid
Body
{
  "params": {
    "namespace": "MyNameSpace",
    "data": [
      {
        "metricName": "UserDefinedName",
        "value": 100.01,
        "labels": {
          "label1": "value1"
        }
      }
    ]
  },
  "systemTags": [],
  "userTags": []
}
Note: 上述示例中systemTags、userTags字段可以省略。列出是为了表示body中可以包含这两个字段。
Curl示例
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X POST -d '{"params":{"namespace":"MyNameSpace","data":[{"metricName":"UserDefinedName","value":100.01,"labels":{"label1":"value1"}}]}}' \
http://localhost:8080/zstack/v1/zwatch/metrics
参数列表
名字 类型 位置 描述 可选值 起始版本
namespace String body(包含在params结构中) 自定义名字空间名称 2.3
data List body(包含在params结构中) 数据 2.3
systemTags (可选) List body 系统标签 2.3
userTags (可选) List body 用户标签 2.3

API返回

该API成功时返回一个空的JSON结构{},出错时返回的JSON结构包含一个error字段,例如:
{
    "error": {
        "code": "SYS.1001",
        "description": "A message or a operation timeout",
        "details": "Create VM on KVM timeout after 300s"
    }
}

SDK示例

Java SDK
PutMetricDataAction action = new PutMetricDataAction();
action.namespace = "MyNameSpace";
action.data = asList([metricName:UserDefinedName, value:100.01, labels:[label1:value1]]);
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
PutMetricDataAction.Result res = action.call();
Python SDK
PutMetricDataAction action = PutMetricDataAction()
action.namespace = "MyNameSpace"
action.data = [[metricName:UserDefinedName, value:100.01, labels:[label1:value1]]]
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
PutMetricDataAction.Result res = action.call()

创建metric数据HTTP接收器(CreateMetricDataHttpReceiver)

API请求

URLs
POST zstack/v1/zwatch/metrics/httpreceivers
Headers
Authorization: OAuth the-session-uuid
Body
{
  "params": {
    "name": "CloudMonitor",
    "url": "http://127.0.0.1/xxx",
    "defaultEnable": true
  },
  "systemTags": [],
  "userTags": []
}
Note: 上述示例中systemTags、userTags字段可以省略。列出是为了表示body中可以包含这两个字段。
Curl示例
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X POST -d '{"params":{"name":"CloudMonitor","url":"http://127.0.0.1/xxx","defaultEnable":true}}' \
http://localhost:8080/zstack/v1/zwatch/metrics/httpreceivers
参数列表
名字 类型 位置 描述 可选值 起始版本
name String body(包含在params结构中) 资源名称 0.6
url String body(包含在params结构中) 0.6
description (可选) String body(包含在params结构中) 资源的详细描述 0.6
defaultEnable (可选) boolean body(包含在params结构中) 0.6
resourceUuid (可选) String body(包含在params结构中) 资源UUID 0.6
tagUuids (可选) List body(包含在params结构中) 标签UUID列表 3.4.0
systemTags (可选) List body 系统标签 0.6
userTags (可选) List body 用户标签 0.6

API返回

返回示例
{
  "inventory": {
    "uuid": "3c4b2b282e4134579df0b8f74fb9a2b7",
    "name": "CloudMonitor",
    "url": "http://127.0.0.1/xxx",
    "createDate": "Nov 14, 2017 2:20:57 PM",
    "lastOpDate": "Nov 14, 2017 2:20:57 PM",
    "state": "Enabled"
  }
}
名字 类型 描述 起始版本
success boolean 0.6
inventory MetricDataHttpReceiverInventory 详情参考inventory 0.6
error ErrorCode 错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error 0.6
#inventory
名字 类型 描述 起始版本
uuid String 资源的UUID,唯一标示该资源 0.6
name String 资源名称 0.6
url String 0.6
description String 资源的详细描述 0.6
createDate Timestamp 创建时间 0.6
lastOpDate Timestamp 最后一次修改时间 0.6
state ReceiverState 详情参考state 0.6
#state
名字 类型 描述 起始版本
Enabled ReceiverState 0.6
Disabled ReceiverState 0.6
#error
名字 类型 描述 起始版本
code String 错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001 0.6
description String 错误的概要描述 0.6
details String 错误的详细信息 0.6
elaboration String 保留字段,默认为null 0.6
opaque LinkedHashMap 保留字段,默认为null 0.6
cause ErrorCode 根错误,引发当前错误的源错误,若无原错误,该字段为null 0.6

SDK示例

Java SDK
CreateMetricDataHttpReceiverAction action = new CreateMetricDataHttpReceiverAction();
action.name = "CloudMonitor";
action.url = "http://127.0.0.1/xxx";
action.defaultEnable = true;
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
CreateMetricDataHttpReceiverAction.Result res = action.call();
Python SDK
CreateMetricDataHttpReceiverAction action = CreateMetricDataHttpReceiverAction()
action.name = "CloudMonitor"
action.url = "http://127.0.0.1/xxx"
action.defaultEnable = true
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
CreateMetricDataHttpReceiverAction.Result res = action.call()

删除metric数据HTTP接收器(DeleteMetricDataHttpReceiver)

API请求

URLs
DELETE zstack/v1/zwatch/metrics/httpreceivers/{uuid}
Headers
Authorization: OAuth the-session-uuid
Curl示例
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X DELETE http://localhost:8080/zstack/v1/zwatch/metrics/httpreceivers/8a02129f4a5b3a2dad0d9136f90d5b08
参数列表
名字 类型 位置 描述 可选值 起始版本
uuid String url 资源的UUID,唯一标示该资源 0.6
deleteMode (可选) String body 删除模式(Permissive / Enforcing,Permissive) 0.6
systemTags (可选) List body 系统标签 0.6
userTags (可选) List body 用户标签 0.6

API返回

该API成功时返回一个空的JSON结构{},出错时返回的JSON结构包含一个error字段,例如:
{
	"error": {
		"code": "SYS.1001",
		"description": "A message or a operation timeout",
		"details": "Create VM on KVM timeout after 300s"
	}
}

SDK示例

Java SDK
DeleteMetricDataHttpReceiverAction action = new DeleteMetricDataHttpReceiverAction();
action.uuid = "8a02129f4a5b3a2dad0d9136f90d5b08";
action.deleteMode = "Permissive";
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
DeleteMetricDataHttpReceiverAction.Result res = action.call();
Python SDK
DeleteMetricDataHttpReceiverAction action = DeleteMetricDataHttpReceiverAction()
action.uuid = "8a02129f4a5b3a2dad0d9136f90d5b08"
action.deleteMode = "Permissive"
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
DeleteMetricDataHttpReceiverAction.Result res = action.call()

查询metric数据HTTP接收器(QueryMetricDataHttpReceiver)

API请求

URLs
GET zstack/v1/zwatch/metrics/httpreceivers
GET zstack/v1/zwatch/metrics/httpreceivers/{uuid}
Headers
Authorization: OAuth the-session-uuid
Curl示例
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X GET http://localhost:8080/zstack/v1/zwatch/metrics/httpreceivers?q=name=CloudMonitor
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X GET http://localhost:8080/zstack/v1/zwatch/metrics/httpreceivers/6e17a72176453e9e9a4b2783d1219fe4

可查询字段

运行CLI命令行工具,输入QueryMetricDataHttpReceiver并按Tab键查看所有可查询字段以及可跨表查询的资源名。

API返回

返回示例
{
  "inventories": [
    {
      "uuid": "77fa620b8d36311ca413c1bfc661c207",
      "name": "CloudMonitor",
      "url": "http://127.0.0.1/xxx",
      "createDate": "Nov 14, 2017 2:20:57 PM",
      "lastOpDate": "Nov 14, 2017 2:20:57 PM",
      "state": "Enabled"
    }
  ]
}
名字 类型 描述 起始版本
success boolean 0.6
inventories List 详情参考inventories 0.6
error ErrorCode 错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error 0.6
#inventories
名字 类型 描述 起始版本
uuid String 资源的UUID,唯一标示该资源 0.6
name String 资源名称 0.6
url String 0.6
description String 资源的详细描述 0.6
createDate Timestamp 创建时间 0.6
lastOpDate Timestamp 最后一次修改时间 0.6
state ReceiverState 详情参考state 0.6
#state
名字 类型 描述 起始版本
Enabled ReceiverState 0.6
Disabled ReceiverState 0.6
#error
名字 类型 描述 起始版本
code String 错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001 0.6
description String 错误的概要描述 0.6
details String 错误的详细信息 0.6
elaboration String 保留字段,默认为null 0.6
opaque LinkedHashMap 保留字段,默认为null 0.6
cause ErrorCode 根错误,引发当前错误的源错误,若无原错误,该字段为null 0.6

SDK示例

Java SDK
QueryMetricDataHttpReceiverAction action = new QueryMetricDataHttpReceiverAction();
action.conditions = asList("name=CloudMonitor");
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
QueryMetricDataHttpReceiverAction.Result res = action.call();
Python SDK
QueryMetricDataHttpReceiverAction action = QueryMetricDataHttpReceiverAction()
action.conditions = ["name=CloudMonitor"]
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
QueryMetricDataHttpReceiverAction.Result res = action.call()

创建metric数据模板(CreateMetricTemplate)

API请求

URLs
POST zstack/v1/zwatch/metrics/httpreceivers/templates
Headers
Authorization: OAuth the-session-uuid
Body
{
  "params": {
    "receiverUuid": "7c10e325f9e232e489062a190cc1dc2a",
    "template": "{  \"metricName\":\"${METRIC_NAME}\",\n  \"regionId\":\"cn-shanghai\",\n  \"instanceId\":\"${RESOURCE_UUID}\",\n  \"resource\":\"vm/${RESOURCE_NAME}\",\n  \"dimensions\":{\n      \"instanceId\":\"${METRIC_LABLES.get(\u0027VMUuid\u0027)}\",\n      \"device\":\"${METRIC_LABLES.get(\u0027DiskDeviceLetter\u0027)}\"\n  },\n  \"value\":${METRIC_VALUE},\n  \"ts\":${METRIC_TIME}\n}",
    "namespace": "ZStack/VM",
    "metricName": "DiskReadOps",
    "labelsJsonStr": "[\u0027VMUuid\u003d95e5885772de4f2bb3e05eba98a43cd0\u0027]"
  },
  "systemTags": [],
  "userTags": []
}
Note: 上述示例中systemTags、userTags字段可以省略。列出是为了表示body中可以包含这两个字段。
Curl示例
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X POST -d '{"params":{"receiverUuid":"7c10e325f9e232e489062a190cc1dc2a","template":"{  \"metricName\":\"${METRIC_NAME}\",\n  \"regionId\":\"cn-shanghai\",\n  \"instanceId\":\"${RESOURCE_UUID}\",\n  \"resource\":\"vm/${RESOURCE_NAME}\",\n  \"dimensions\":{\n      \"instanceId\":\"${METRIC_LABLES.get('VMUuid')}\",\n      \"device\":\"${METRIC_LABLES.get('DiskDeviceLetter')}\"\n  },\n  \"value\":${METRIC_VALUE},\n  \"ts\":${METRIC_TIME}\n}","namespace":"ZStack/VM","metricName":"DiskReadOps","labelsJsonStr":"['VMUuid=95e5885772de4f2bb3e05eba98a43cd0']"}}' \
http://localhost:8080/zstack/v1/zwatch/metrics/httpreceivers/templates
参数列表
名字 类型 位置 描述 可选值 起始版本
receiverUuid String body(包含在params结构中) 0.6
template String body(包含在params结构中) 0.6
namespace String body(包含在params结构中) 0.6
metricName String body(包含在params结构中) 0.6
labelsJsonStr (可选) String body(包含在params结构中) 0.6
description (可选) String body(包含在params结构中) 资源的详细描述 0.6
resourceUuid (可选) String body(包含在params结构中) 资源UUID 0.6
tagUuids (可选) List body(包含在params结构中) 标签UUID列表 3.4.0
systemTags (可选) List body 系统标签 0.6
userTags (可选) List body 用户标签 0.6

API返回

返回示例
{
  "inventory": {
    "uuid": "b143e113525d3fbaa56bf9be7fa15ccf",
    "receiverUuid": "95d0c874bdec350cbb963f97ae9f3a13",
    "template": "{  \"metricName\":\"${METRIC_NAME}\",\n  \"regionId\":\"cn-shanghai\",\n  \"instanceId\":\"${RESOURCE_UUID}\",\n  \"resource\":\"vm/${RESOURCE_NAME}\",\n  \"dimensions\":{\n      \"instanceId\":\"${METRIC_LABLES.get(\u0027VMUuid\u0027)}\",\n      \"device\":\"${METRIC_LABLES.get(\u0027DiskDeviceLetter\u0027)}\"\n  },\n  \"value\":${METRIC_VALUE},\n  \"ts\":${METRIC_TIME}\n}",
    "namespace": "ZStack/VM",
    "metricName": "DiskReadOps",
    "labelsJsonStr": "[\u0027VMUuid\u003d95e5885772de4f2bb3e05eba98a43cd0\u0027]",
    "createDate": "Nov 14, 2017 2:20:57 PM",
    "lastOpDate": "Nov 14, 2017 2:20:57 PM"
  }
}
名字 类型 描述 起始版本
success boolean 0.6
inventory MetricTemplateInventory 详情参考inventory 0.6
error ErrorCode 错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error 0.6
#inventory
名字 类型 描述 起始版本
uuid String 资源的UUID,唯一标示该资源 0.6
receiverUuid String 0.6
template String 0.6
namespace String 0.6
metricName String 0.6
labelsJsonStr String 0.6
description String 资源的详细描述 0.6
createDate Timestamp 创建时间 0.6
lastOpDate Timestamp 最后一次修改时间 0.6
#error
名字 类型 描述 起始版本
code String 错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001 0.6
description String 错误的概要描述 0.6
details String 错误的详细信息 0.6
elaboration String 保留字段,默认为null 0.6
opaque LinkedHashMap 保留字段,默认为null 0.6
cause ErrorCode 根错误,引发当前错误的源错误,若无原错误,该字段为null 0.6

SDK示例

Java SDK
CreateMetricTemplateAction action = new CreateMetricTemplateAction();
action.receiverUuid = "7c10e325f9e232e489062a190cc1dc2a";
action.template = "{  "metricName":"${METRIC_NAME}",
  "regionId":"cn-shanghai",
  "instanceId":"${RESOURCE_UUID}",
  "resource":"vm/${RESOURCE_NAME}",
  "dimensions":{
      "instanceId":"${METRIC_LABLES.get('VMUuid')}",
      "device":"${METRIC_LABLES.get('DiskDeviceLetter')}"
  },
  "value":${METRIC_VALUE},
  "ts":${METRIC_TIME}
}";
action.namespace = "ZStack/VM";
action.metricName = "DiskReadOps";
action.labelsJsonStr = "['VMUuid=95e5885772de4f2bb3e05eba98a43cd0']";
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
CreateMetricTemplateAction.Result res = action.call();
Python SDK
CreateMetricTemplateAction action = CreateMetricTemplateAction()
action.receiverUuid = "7c10e325f9e232e489062a190cc1dc2a"
action.template = "{  "metricName":"${METRIC_NAME}",
  "regionId":"cn-shanghai",
  "instanceId":"${RESOURCE_UUID}",
  "resource":"vm/${RESOURCE_NAME}",
  "dimensions":{
      "instanceId":"${METRIC_LABLES.get('VMUuid')}",
      "device":"${METRIC_LABLES.get('DiskDeviceLetter')}"
  },
  "value":${METRIC_VALUE},
  "ts":${METRIC_TIME}
}"
action.namespace = "ZStack/VM"
action.metricName = "DiskReadOps"
action.labelsJsonStr = "['VMUuid=95e5885772de4f2bb3e05eba98a43cd0']"
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
CreateMetricTemplateAction.Result res = action.call()

删除metric数据模板(DeleteMetricTemplate)

API请求

URLs
DELETE zstack/v1/zwatch/metrics/httpreceivers/templates/{uuid}
Headers
Authorization: OAuth the-session-uuid
Curl示例
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X DELETE http://localhost:8080/zstack/v1/zwatch/metrics/httpreceivers/templates/0187f2f1cfc83e638f306f9af28b3fb5
参数列表
名字 类型 位置 描述 可选值 起始版本
uuid String url 资源的UUID,唯一标示该资源 0.6
deleteMode (可选) String body 删除模式(Permissive / Enforcing,Permissive) 0.6
systemTags (可选) List body 系统标签 0.6
userTags (可选) List body 用户标签 0.6

API返回

该API成功时返回一个空的JSON结构{},出错时返回的JSON结构包含一个error字段,例如:
{
	"error": {
		"code": "SYS.1001",
		"description": "A message or a operation timeout",
		"details": "Create VM on KVM timeout after 300s"
	}
}

SDK示例

Java SDK
DeleteMetricTemplateAction action = new DeleteMetricTemplateAction();
action.uuid = "0187f2f1cfc83e638f306f9af28b3fb5";
action.deleteMode = "Permissive";
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
DeleteMetricTemplateAction.Result res = action.call();
Python SDK
DeleteMetricTemplateAction action = DeleteMetricTemplateAction()
action.uuid = "0187f2f1cfc83e638f306f9af28b3fb5"
action.deleteMode = "Permissive"
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
DeleteMetricTemplateAction.Result res = action.call()

查询metric数据模板(QueryMetricTemplate)

API请求

URLs
GET zstack/v1/zwatch/metrics/httpreceivers/templates
GET zstack/v1/zwatch/metrics/httpreceivers/templates/{uuid}
Headers
Authorization: OAuth the-session-uuid
Curl示例
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X GET http://localhost:8080/zstack/v1/zwatch/metrics/httpreceivers/templates?q=receiverUuid=13213154f64e33bb8ad461956981a6e2
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X GET http://localhost:8080/zstack/v1/zwatch/metrics/httpreceivers/templates/98a42f1af96e3c89b59e87bb20cc6421

可查询字段

运行CLI命令行工具,输入QueryMetricTemplate并按Tab键查看所有可查询字段以及可跨表查询的资源名。

API返回

返回示例
{
  "inventories": [
    {
      "uuid": "77fa620b8d36311ca413c1bfc661c207",
      "name": "CloudMonitor",
      "url": "http://127.0.0.1/xxx",
      "createDate": "Nov 14, 2017 2:20:57 PM",
      "lastOpDate": "Nov 14, 2017 2:20:57 PM",
      "state": "Enabled"
    }
  ]
}
名字 类型 描述 起始版本
success boolean 0.6
inventories List 详情参考inventories 0.6
error ErrorCode 错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error 0.6
#inventories
名字 类型 描述 起始版本
uuid String 资源的UUID,唯一标示该资源 0.6
name String 资源名称 0.6
url String 0.6
description String 资源的详细描述 0.6
createDate Timestamp 创建时间 0.6
lastOpDate Timestamp 最后一次修改时间 0.6
state ReceiverState 详情参考state 0.6
#state
名字 类型 描述 起始版本
Enabled ReceiverState 0.6
Disabled ReceiverState 0.6
#error
名字 类型 描述 起始版本
code String 错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001 0.6
description String 错误的概要描述 0.6
details String 错误的详细信息 0.6
elaboration String 保留字段,默认为null 0.6
opaque LinkedHashMap 保留字段,默认为null 0.6
cause ErrorCode 根错误,引发当前错误的源错误,若无原错误,该字段为null 0.6

SDK示例

Java SDK
QueryMetricTemplateAction action = new QueryMetricTemplateAction();
action.conditions = asList("receiverUuid=21eee98608ce3cc580d7572e6ee47fea");
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
QueryMetricTemplateAction.Result res = action.call();
Python SDK
QueryMetricTemplateAction action = QueryMetricTemplateAction()
action.conditions = ["receiverUuid=aca6437c53a4348eb6d8c20fe0cf054e"]
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
QueryMetricTemplateAction.Result res = action.call()
开发手册 | ZStack ZSphere · ZVF | ZStack 资源中心