Create a Metric Template

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('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']"
  },
  "systemTags": [],
  "userTags": []
}

The systemTags and userTags fields in the above example are optional. They are listed to indicate that the body can contain these two fields.

Curl Example

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

Parameter List

NameTypeLocationDescriptionAllowed ValuesStarting Version
receiverUuidStringbody (included in the params structure)  0.6
templateStringbody (included in the params structure)  0.6
namespaceStringbody (included in the params structure)  0.6
metricNameStringbody (included in the params structure)  0.6
labelsJsonStr (optional)Stringbody (included in the params structure)  0.6
description (optional)Stringbody (included in the params structure)Detailed description of the resource 0.6
resourceUuid (optional)Stringbody (included in the params structure)Resource UUID 0.6
tagUuids (optional)Listbody (included in the params structure)Tag UUID list 3.4.0
systemTags (optional)ListbodySystem tags 0.6
userTags (optional)ListbodyUser tags 0.6

API Response

Response Example

{
  "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('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']",
    "createDate": "Nov 14, 2017 2:20:57 PM",
    "lastOpDate": "Nov 14, 2017 2:20:57 PM"
  }
}
NameTypeDescriptionStarting Version
successboolean 0.6
inventoryMetricTemplateInventoryFor details, see inventory0.6
errorErrorCodeError code. If not null, the operation failed. This field is null when the operation succeeds. For details, see error0.6

inventory

NameTypeDescriptionStarting Version
uuidStringResource UUID. Uniquely identifies the resource0.6
receiverUuidString 0.6
templateString 0.6
namespaceString 0.6
metricNameString 0.6
labelsJsonStrString 0.6
descriptionStringDetailed description of the resource0.6
createDateTimestampCreation time0.6
lastOpDateTimestampLast modification time0.6

error

NameTypeDescriptionStarting Version
codeStringError code. The globally unique error identifier, for example, SYS.1000, HOST.10010.6
descriptionStringBrief description of the error0.6
detailsStringDetailed error information0.6
elaborationStringReserved field. Default is null0.6
opaqueLinkedHashMapReserved field. Default is null0.6
causeErrorCodeRoot error. The source error that caused the current error. This field is null if no root error exists0.6

SDK Examples

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()