Adding Monitoring Data
Function
This API is used to add one or more monitoring data records to a server.
Calling Method
For details, see Calling APIs.
URI
POST /v1/{project_id}/ams/report/metricdata
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
project_id |
Yes |
String |
Project ID obtained from IAM. Generally, a project ID contains 32 characters. |
Request Parameters
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
X-Auth-Token |
Yes |
String |
User token obtained from IAM. |
Content-Type |
Yes |
String |
Content type, which is application/json. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
[items] |
Yes |
Array of MetricDataItem objects |
Metric parameters. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
collect_time |
Yes |
Long |
Data collection time (UNIX timestamp, in ms), which ranges from the last 24 hours to the next 0.5 hour. The following requirement needs to be met: Current UTC time – Data collection time ≤ 24 hours, or Data collection time – Current UTC time ≤ 30 minutes If the data reporting time is earlier than 08:00 of the current day, only the data generated after 08:00 of the current day is displayed on the metric monitoring page. |
metric |
Yes |
MetricItemInfo object |
Metric details. |
values |
Yes |
Array of ValueData objects |
Metric value. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
dimensions |
Yes |
Array of Dimension2 objects |
List of metric dimensions. A maximum of 50 dimensions are supported. Each dimension is in JSON format. The structure is as follows: dimension.name: 1–32 characters. dimension.value: 1–64 characters. |
namespace |
Yes |
String |
Metric namespace. It cannot contain colons (:). It must be in the format of "service.item". The value must contain 3 to 32 characters starting with a letter. Only letters, digits, and underscores (_) are allowed. In addition, "service" cannot be "PAAS". |
Response Parameters
Status code: 200
Parameter |
Type |
Description |
---|---|---|
errorCode |
String |
Response code. |
errorMessage |
String |
Response message. |
Example Requests
Add a piece of monitoring data to the server. (In the following example, set "collect_time" to the latest timestamp.)
https://{Endpoint}/v1/{project_id}/ams/report/metricdata [ { "metric" : { "namespace" : "NOPAAS.ESC", "dimensions" : [ { "name" : "instance_id", "value" : "instance-101" } ] }, "values" : [ { "unit" : "percent", "metric_name" : "cpu_util", "type" : "int", "value" : 35 } ], "collect_time" : 1467787152000 } ]
Example Responses
Status code: 200
OK: The request is successful.
{ "errorCode" : "SVCSTG_AMS_2000000", "errorMessage" : "success" }
SDK Sample Code
The SDK sample code is as follows.
Java
Add a piece of monitoring data to the server. (In the following example, set "collect_time" to the latest timestamp.)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.aom.v2.region.AomRegion; import com.huaweicloud.sdk.aom.v2.*; import com.huaweicloud.sdk.aom.v2.model.*; import java.util.List; import java.util.ArrayList; public class AddMetricDataSolution { public static void main(String[] args) { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment String ak = System.getenv("CLOUD_SDK_AK"); String sk = System.getenv("CLOUD_SDK_SK"); String projectId = "{project_id}"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); AomClient client = AomClient.newBuilder() .withCredential(auth) .withRegion(AomRegion.valueOf("<YOUR REGION>")) .build(); AddMetricDataRequest request = new AddMetricDataRequest(); List<ValueData> listBodyValues = new ArrayList<>(); listBodyValues.add( new ValueData() .withMetricName("cpu_util") .withType(ValueData.TypeEnum.fromValue("int")) .withUnit("percent") .withValue((double)35) ); List<Dimension2> listMetricDimensions = new ArrayList<>(); listMetricDimensions.add( new Dimension2() .withName("instance_id") .withValue("instance-101") ); MetricItemInfo metricBody = new MetricItemInfo(); metricBody.withDimensions(listMetricDimensions) .withNamespace("NOPAAS.ESC"); List<MetricDataItem> listbodyBody = new ArrayList<>(); listbodyBody.add( new MetricDataItem() .withCollectTime(1467787152000L) .withMetric(metricBody) .withValues(listBodyValues) ); request.withBody(listbodyBody); try { AddMetricDataResponse response = client.addMetricData(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } } |
Python
Add a piece of monitoring data to the server. (In the following example, set "collect_time" to the latest timestamp.)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkaom.v2.region.aom_region import AomRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkaom.v2 import * if __name__ == "__main__": # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = AomClient.new_builder() \ .with_credentials(credentials) \ .with_region(AomRegion.value_of("<YOUR REGION>")) \ .build() try: request = AddMetricDataRequest() listValuesBody = [ ValueData( metric_name="cpu_util", type="int", unit="percent", value=35 ) ] listDimensionsMetric = [ Dimension2( name="instance_id", value="instance-101" ) ] metricBody = MetricItemInfo( dimensions=listDimensionsMetric, namespace="NOPAAS.ESC" ) listBodybody = [ MetricDataItem( collect_time=1467787152000, metric=metricBody, values=listValuesBody ) ] request.body = listBodybody response = client.add_metric_data(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) |
Go
Add a piece of monitoring data to the server. (In the following example, set "collect_time" to the latest timestamp.)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" aom "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v2" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v2/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v2/region" ) func main() { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak := os.Getenv("CLOUD_SDK_AK") sk := os.Getenv("CLOUD_SDK_SK") projectId := "{project_id}" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := aom.NewAomClient( aom.AomClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.AddMetricDataRequest{} typeValues:= model.GetValueDataTypeEnum().INT unitValues:= "percent" var listValuesBody = []model.ValueData{ { MetricName: "cpu_util", Type: &typeValues, Unit: &unitValues, Value: float64(35), }, } var listDimensionsMetric = []model.Dimension2{ { Name: "instance_id", Value: "instance-101", }, } metricBody := &model.MetricItemInfo{ Dimensions: listDimensionsMetric, Namespace: "NOPAAS.ESC", } var listBodybody = []model.MetricDataItem{ { CollectTime: int64(1467787152000), Metric: metricBody, Values: listValuesBody, }, } request.Body = &listBodybody response, err := client.AddMetricData(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
More
For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.
Status Codes
Status Code |
Description |
---|---|
200 |
OK: The request is successful. |
400 |
Bad Request: The request is invalid. The client should not repeat the request without modifications. |
401 |
Unauthorized: The authentication information is incorrect or invalid. |
403 |
Forbidden: The request is rejected. The server has received the request and understood it, but the server refuses to respond to it. The client should not repeat the request without modifications. |
500 |
Internal Server Error: The server is able to receive the request but unable to understand the request. |
503 |
Service Unavailable: The requested service is invalid. The client should not repeat the request without modifications. |
Error Codes
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot