Updated on 2024-04-15 GMT+08:00

Querying Metrics

Function

This API is used to query the metrics that can be monitored in the system. You can query specific metrics by specifying a namespace, metric name, dimension, and resource ID (format: resType_resId). You can also specify the start position and the maximum number of returned records for a pagination query.

URI

POST /v1/{project_id}/ams/metrics

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID obtained from IAM. Generally, a project ID contains 32 characters.

Table 2 Query Parameters

Parameter

Mandatory

Type

Description

type

No

String

Metric query mode.

limit

No

String

Number of records that can be returned. Value range: 1–1000. Default value: 1000.

start

No

String

Start position of a pagination query. The value is a non-negative integer.

Request Parameters

Table 3 Request header 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.

Enumeration values:

  • application/json

X-Aom-Prometheus-Id

No

String

Prometheus instance ID. If this parameter is left blank, the default Prometheus instance is used.

Table 4 Request body parameters

Parameter

Mandatory

Type

Description

inventoryId

No

String

Resource ID, which must be in the format of resType_resId. Enumerated values of resType: host, application, instance, container, process, network, storage, and volume. When type (a URI parameter) is inventory, this parameter instead of metricItems is used for associated metric queries.

metricItems

No

Array of QueryMetricItemOptionParam objects

If type (a URI parameter) is not inventory, the information carried by the array is used to query metrics.

Table 5 QueryMetricItemOptionParam

Parameter

Mandatory

Type

Description

dimensions

No

Array of Dimension objects

List of metric dimensions.

metricName

No

String

Metric name. Length: 1 to 1000 characters. Values: cpuUage: CPU usage. cpuCoreUsed: used CPU cores. Reported custom metrics.

namespace

Yes

String

Metric namespace. Values:

  • PAAS.CONTAINER: namespace of component, instance, process, and container metrics.

  • PAAS.NODE: namespace of host, network, disk, and file system metrics.

  • PAAS.SLA: namespace of SLA metrics.

  • PAAS.AGGR: namespace of cluster metrics.

  • CUSTOM.Prometheus: namespace of Prometheus metrics.

  • Namespace of custom metrics.

Enumeration values:

  • PAAS.CONTAINER

  • PAAS.NODE

  • PAAS.SLA

  • PAAS.AGGR

  • CUSTOMMETRICS

Table 6 Dimension

Parameter

Mandatory

Type

Description

name

Yes

String

Dimension name. It cannot be empty. Enter up to 255 characters.

value

No

String

Dimension value. Enter up to 1024 characters.

Response Parameters

Status code: 200

Table 7 Response body parameters

Parameter

Type

Description

errorCode

String

Response code.

errorMessage

String

Response message.

metrics

Array of MetricItemResultAPI objects

Metric list.

metaData

MetaData object

Metadata, including pagination information.

Table 8 MetricItemResultAPI

Parameter

Type

Description

dimensions

Array of Dimension objects

List of metric dimensions.

dimensionvaluehash

String

Metric hash value.

metricName

String

Metric name.

namespace

String

Namespace.

unit

String

Metric unit.

Table 9 Dimension

Parameter

Type

Description

name

String

Dimension name. It cannot be empty. Enter up to 255 characters.

value

String

Dimension value. Enter up to 1024 characters.

Table 10 MetaData

Parameter

Type

Description

count

Integer

Number of records that can be returned.

start

String

Start of the next page, which is used for pagination. null: No more data.

total

Integer

Total number of records.

Example Requests

  • Query metrics by inventory ID.

    POST https://{Endpoint}/v1/{project_id}/ams/metrics?type=inventory
    
    {
      "inventoryId" : "application_************7-b56f-fa163e3fee10"
    }
  • Query metrics by namespace, appName, and clusterName.

    POST https://{Endpoint}/v1/{project_id}/ams/metrics
    
    {
      "metricItems" : [ {
        "namespace" : "PAAS.CONTAINER",
        "dimensions" : [ {
          "name" : "appName",
          "value" : "demo"
        }, {
          "name" : "clusterName",
          "value" : "test"
        } ]
      } ]
    }

Example Responses

Status code: 200

OK

The request is successful.

{
  "errorCode" : "SVCSTG_AMS_2000000",
  "errorMessage" : "success",
  "metaData" : {
    "count" : 1,
    "start" : null,
    "total" : 1
  },
  "metrics" : [ {
    "namespace" : "abc",
    "metricName" : "cpuUsage",
    "unit" : "Percent",
    "dimensions" : [ {
      "name" : "instance_id",
      "value" : "demo1"
    } ]
  } ]
}

Status Codes

Status Code

Description

200

OK

The request is successful.

400

Bad Request

Invalid request. The client should not repeat the request without modifications.

401

Unauthorized

The authorization information is incorrect or invalid.

403

ForbiddenThe 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.