Help Center > > API Reference> APIs> Monitoring APIs> Querying Metrics

Querying Metrics

Updated at: Nov 25, 2019 GMT+08:00

Function

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

URI

POST /v1/{project_id}/ams/metrics?type={type}&limit={limit}&start={start}

Table 1 describes the parameters.

Table 1 Parameters

Parameter

Mandatory

Description

project_id

Yes

Project ID applied from Identity and Access Management (IAM). Generally, it is a string containing 32 characters.

type

No

Metric query mode. The information carried by metricItems in the request body is used to query metrics.

limit

No

Maximum number of returned data records. Value range: 1–1000. Default value: 1000.

start

No

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

Request

Request parameters

Table 2 describes the request parameters.

Table 2 Request parameters

Parameter

Mandatory

Type

Value Range

Description

metricItems

No

Array

-

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

namespace

Yes

String

PAAS.CONTAINER, PAAS.NODE, PAAS.SLA, PAAS.AGGR, CUSTOMMETRICS, and so on.

Metric namespace.

PAAS.CONTAINER: application metric.

PAAS.NODE: node metric.

PAAS.SLA: Service Level Agreement (SLA) metric.

PAAS.AGGR: cluster metric.

CUSTOMMETRICS: custom metric.

dimensions

No

Array

-

Metric dimension.

dimensions.name: dimension name, such as clusterName, clusterId, appName, appID, deploymentName, podName, podID, containerName, or containerID.

dimensions.value: dimension value, such as a specific application instance ID.

metricName

No

String

1–255 characters.

Metric name.

Request headers

Table 3 describes the request headers.

Table 3 Request headers

Name

Mandatory

Description

X-Auth-Token

Yes

User token obtained from IAM.

Content-Type

Yes

Content type, which is application/json.

Example request

(Query by namespace+appName+clusterName)

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

Response

Response parameters

Table 4 describes the response parameters.

Table 4 Response parameters

Parameter

Type

Description

errorCode

String

Response code. SVCSTG_AMS_2000000: Success response.

errorMessage

String

Response message.

metrics

Array

List of metrics.

namespace

String

Namespace.

metricName

String

Metric name.

unit

String

Metric unit.

dimensions

Array

List of metric dimensions.

Example response

{ 
    "errorCode": "SVCSTG_AMS_2000000", 
    "errorMessage": "success", 
    "metrics": [{ 
        "namespace": "abc", 
        "metricName": "cpuUsage", 
        "unit":"Percent", 
        "dimensions": [{ 
                    "name": "instance_id", 
                    "value": "demo1" 
        }]     
    }] 
}

Status Code

  • Success response

    Table 5 describes the status code.

    Table 5 Status code

    Status Code

    Message

    Description

    200

    OK

    The request has succeeded.

  • Error response

    Table 6 describes the status codes. For more information, see Status Codes.

    Table 6 Status codes

    Status Code

    Message

    Description

    400

    BadRequest

    The request is invalid.

    The client should not repeat the request without modifications.

    401

    Unauthorized

    The authorization information provided by the client is incorrect or invalid.

    403

    Forbidden

    The request is rejected.

    The server has received the request and understood it, but the server is refusing to respond to it. The client should not repeat the request without modifications.

    500

    InternalServerError

    The server is able to receive the request but unable to understand the request.

    503

    ServiceUnavailable

    The requested service is invalid.

    The client should not repeat the request without modifications.

Error Code

Table 7 Error codes

Error Code

Message

Solution

SVCSTG_AMS_4000101

Invalid namespace.

Check whether the parameter meets requirements.

SVCSTG_AMS_4000102

Invalid inventoryId.

Check whether the parameter meets requirements.

SVCSTG_AMS_4000103

ProjectId is left blank.

Check whether the parameter meets requirements.

SVCSTG_AMS_4000105

Invalid limit.

Check whether the parameter meets requirements.

SVCSTG_AMS_4000106

Invalid start.

Check whether the parameter meets requirements.

SVCSTG_AMS_4000109

Invalid metricName.

Check whether the parameter meets requirements.

SVCSTG_AMS_5030001

The Cassandra session is null.

Contact the administrator.

Did you find this page helpful?

Submit successfully!

Thank you for your feedback. Your feedback helps make our documentation better.

Failed to submit the feedback. Please try again later.

Which of the following issues have you encountered?







Please complete at least one feedback item.

Content most length 200 character

Content is empty.

OK Cancel