查询指标
功能介绍
该接口用于查询系统当前可监控的指标列表,可以指定指标命名空间、指标名称、维度、所属资源的编号(格式为:resType_resId),分页查询的起始位置和返回的最大记录条数。
调用方法
请参见如何调用API。
URI
POST /v1/{project_id}/ams/metrics
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
租户从IAM申请到的projectid,一般为32位字符串。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
type |
否 |
String |
指标查询方式。 |
limit |
否 |
String |
用于限制本次返回的结果数据条数。 取值范围(0,1000],默认值为1000。 最小长度:0 最大长度:4 |
start |
否 |
String |
分页查询起始位置,为非负整数。 |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
X-Auth-Token |
是 |
String |
从IAM服务获取的用户Token。 |
Content-Type |
是 |
String |
指定类型为application/json。 枚举值:
|
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
inventoryId |
否 |
String |
资源编号,格式为resType_resId。其中resType部分的枚举值为:host,application,instance, container,process,network,storage, volume。当URI参数中的type取值为“inventory”时,通过该参数查询关联的指标,不再使用metricItems数组中的信息。 |
metricItems |
否 |
Array of QueryMetricItemOptionParam objects |
当URI参数中的type取值不为“inventory”时,就通过该数组传递的参数信息进行指标查询。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
dimensions |
否 |
Array of Dimension objects |
指标维度列表。 |
metricName |
否 |
String |
指标名称。名称长度取值范围为1~255个字符。取值范围:AOM提供的基础指标,cpuUsage、cpuCoreUsed等。cpuUsage:cpu使用率;cpuCoreUsed:cpu内核占用;用户上报的自定义指标名称。 |
namespace |
是 |
String |
指标命名空间。取值范围:PAAS.CONTAINER:组件指标、实例指标、进程指标和容器指标的命名空间,PAAS.NODE: 主机指标、网络指标、磁盘指标和文件系统指标的命名空间,PAAS.SLA:SLA指标的命名空间,PAAS.AGGR:集群指标的命名空间,CUSTOMMETRICS:默认的自定义指标的命名空间。 枚举值:
|
响应参数
状态码: 200
参数 |
参数类型 |
描述 |
---|---|---|
metaData |
MetaDataSeries object |
查询结果元数据信息,包括分页信息等。 |
metrics |
Array of MetricItemResultAPI objects |
指标对象列表。 |
参数 |
参数类型 |
描述 |
---|---|---|
count |
Integer |
当前返回结果条数。 |
offset |
Integer |
下一个开始的标记,用于分页,null表示无更多数据。 |
total |
Integer |
总条数。 |
nextToken |
Integer |
偏移量。 |
参数 |
参数类型 |
描述 |
---|---|---|
dimensions |
Array of Dimension objects |
指标维度列表。 |
dimensionvaluehash |
String |
指标哈希值。 |
metricName |
String |
指标名称。 |
namespace |
String |
命名空间。 |
unit |
String |
指标单位。 |
请求示例
- 通过namespace+appName+clusterName查询指标列表。
https://{Endpoint}/v1/{project_id}/ams/metrics { "metricItems" : [ { "namespace" : "PAAS.CONTAINER", "dimensions" : [ { "name" : "appName", "value" : "aomApp" }, { "name" : "clusterName", "value" : "aomCluster" } ] } ] }
- 通过inventoryId查询指标列表。
https://{Endpoint}/v1/{project_id}/ams/metrics?type=inventory { "inventoryId" : "application_xxxxxxxx-xxxx-xxxx-xxxx-xxxxx3fee10" }
响应示例
状态码: 200
OK 请求执行完成。
{ "errorCode" : "SVCSTG_AMS_2000000", "errorMessage" : "success", "metaData" : { "count" : 1, "offset" : 1, "nextToken" : null, "total" : 1 }, "metrics" : [ { "namespace" : "PAAS.CONTAINER", "metricName" : "aom_process_cpu_usage", "unit" : "Percent", "dimensions" : [ { "name" : "appName", "value" : "aomApp" } ] } ] }
SDK代码示例
SDK代码示例如下。
- 通过namespace+appName+clusterName查询指标列表。
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
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 ListMetricItemsSolution { 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(); ListMetricItemsRequest request = new ListMetricItemsRequest(); MetricAPIQueryItemParam body = new MetricAPIQueryItemParam(); List<Dimension> listMetricItemsDimensions = new ArrayList<>(); listMetricItemsDimensions.add( new Dimension() .withName("appName") .withValue("aomApp") ); listMetricItemsDimensions.add( new Dimension() .withName("clusterName") .withValue("aomCluster") ); List<QueryMetricItemOptionParam> listbodyMetricItems = new ArrayList<>(); listbodyMetricItems.add( new QueryMetricItemOptionParam() .withDimensions(listMetricItemsDimensions) .withNamespace(QueryMetricItemOptionParam.NamespaceEnum.fromValue("PAAS.CONTAINER")) ); body.withMetricItems(listbodyMetricItems); request.withBody(body); try { ListMetricItemsResponse response = client.listMetricItems(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()); } } }
- 通过inventoryId查询指标列表。
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
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.*; public class ListMetricItemsSolution { 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(); ListMetricItemsRequest request = new ListMetricItemsRequest(); MetricAPIQueryItemParam body = new MetricAPIQueryItemParam(); body.withInventoryId("application_xxxxxxxx-xxxx-xxxx-xxxx-xxxxx3fee10"); request.withBody(body); try { ListMetricItemsResponse response = client.listMetricItems(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()); } } }
- 通过namespace+appName+clusterName查询指标列表。
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
# 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 = ListMetricItemsRequest() listDimensionsMetricItems = [ Dimension( name="appName", value="aomApp" ), Dimension( name="clusterName", value="aomCluster" ) ] listMetricItemsbody = [ QueryMetricItemOptionParam( dimensions=listDimensionsMetricItems, namespace="PAAS.CONTAINER" ) ] request.body = MetricAPIQueryItemParam( metric_items=listMetricItemsbody ) response = client.list_metric_items(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
- 通过inventoryId查询指标列表。
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
# 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 = ListMetricItemsRequest() request.body = MetricAPIQueryItemParam( inventory_id="application_xxxxxxxx-xxxx-xxxx-xxxx-xxxxx3fee10" ) response = client.list_metric_items(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
- 通过namespace+appName+clusterName查询指标列表。
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
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.ListMetricItemsRequest{} var listDimensionsMetricItems = []model.Dimension{ { Name: "appName", Value: "aomApp", }, { Name: "clusterName", Value: "aomCluster", }, } var listMetricItemsbody = []model.QueryMetricItemOptionParam{ { Dimensions: &listDimensionsMetricItems, Namespace: model.GetQueryMetricItemOptionParamNamespaceEnum().PAAS_CONTAINER, }, } request.Body = &model.MetricApiQueryItemParam{ MetricItems: &listMetricItemsbody, } response, err := client.ListMetricItems(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
- 通过inventoryId查询指标列表。
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
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.ListMetricItemsRequest{} inventoryIdMetricApiQueryItemParam:= "application_xxxxxxxx-xxxx-xxxx-xxxx-xxxxx3fee10" request.Body = &model.MetricApiQueryItemParam{ InventoryId: &inventoryIdMetricApiQueryItemParam, } response, err := client.ListMetricItems(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
200 |
OK 请求执行完成。 |
400 |
BadRequest 非法请求。建议直接修改该请求,不要重试该请求。 |
401 |
Unauthorized 在客户端提供认证信息后,返回该状态码,表明服务端指出客户端所提供的认证信息不正确或非法。 |
403 |
Forbidden 请求被拒绝访问。返回该状态码,表明请求能够到达服务端,且服务端能够理解用户请求,但是拒绝做更多的事情,因为该请求被设置为拒绝访问,建议直接修改该请求,不要重试该请求。 |
500 |
InternalServerError 表明服务端能被请求访问到,但是不能理解用户的请求。 |
503 |
ServiceUnavailable 被请求的服务无效。建议直接修改该请求,不要重试该请求。 |
错误码
请参见错误码。