Store Custom Metric Data

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": []
}

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":{"namespace":"MyNameSpace","data":[{"metricName":"UserDefinedName","value":100.01,"labels":{"label1":"value1"}}]}}' \
http://localhost:8080/zstack/v1/zwatch/metrics

Parameter List

NameTypeLocationDescriptionAllowed ValuesStarting Version
namespaceStringbody (included in the params structure)Custom namespace name 2.3
dataListbody (included in the params structure)Data 2.3
systemTags (optional)ListbodySystem tags 2.3
userTags (optional)ListbodyUser tags 2.3

API Response

On success, this API returns an empty JSON structure {}. On failure, the returned JSON structure contains an error field, for example:

{
  "error": {
    "code": "SYS.1001",
    "description": "A message or a operation timeout",
    "details": "Create VM on KVM timeout after 300s"
  }
}

SDK Examples

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