Updated on 2022-02-22 GMT+08:00

Querying the Metric List

Function

This API is used to query the metric list. You can specify the namespace, metric, dimension, sorting order, start records, and the maximum number of records when using this API to query metrics.

URI

GET /V1.0/{project_id}/metrics

  • Parameter description
    Table 1 Parameter description

    Parameter

    Mandatory

    Description

    project_id

    Yes

    Specifies the project ID.

    For details about how to obtain the project ID, see Obtaining a Project ID.

    Table 2 Query parameter description

    Parameter

    Mandatory

    Type

    Description

    namespace

    No

    String

    Query the namespace of a service. For example, see Namespace for ECS namespace.

    The value must be in the service.item format and can contain 3 to 32 characters. service and item each must be a string that starts with a letter and contains only uppercase letters, lowercase letters, digits, and underscores (_).

    metric_name

    No

    String

    Specifies the metric ID. For example, if the monitoring metric of an ECS is CPU usage, metric_name is cpu_util.

    dim

    No

    String

    Specifies the dimension. For example, the dimension of an ECS is instance_id.

    A maximum of three dimensions are supported, and the dimensions are numbered from 0 in dim.{i}=key,value format. The key cannot exceed 32 characters and the value cannot exceed 256 characters.

    Single dimension: dim.0=instance_id,6f3c6f91-4b24-4e1b-b7d1-a94ac1cb011d

    Multiple dimensions: dim.0=key,value&dim.1=key,value

    start

    No

    String

    Specifies the paging start value.

    The format is namespace.metric_name.key:value.

    Example: start=SYS.ECS.cpu_util.instance_id:d9112af5-6913-4f3b-bd0a-3f96711e004d.

    limit

    No

    Integer

    The value ranges from 1 to 1000, and is 1000 by default.

    This parameter is used to limit the number of query results.

    order

    No

    String

    Specifies the result sorting method, which is sorted by timestamp.

    The default value is desc.

    • asc: The query results are displayed in the ascending order.
    • desc: The query results are displayed in the descending order.
  • Example request
    Request example 1: Query the list of all metrics that can be monitored.
    GET https://{Cloud Eye endpoint}/V1.0/{project_id}/metrics
    Request example 2: Query the CPU usage of the ECS whose ID is 6f3c6f91-4b24-4e1b-b7d1-a94ac1cb011d. Retain 10 records in descending order by timestamp.
    GET https://{Cloud Eye endpoint}/V1.0/{project_id}/metrics?namespace=SYS.ECS&metric_name=cpu_util&dim.0=instance_id,6f3c6f91-4b24-4e1b-b7d1-a94ac1cb011d&limit=10&order=desc

Request

None

Response

  • Response parameters
    Table 3 Response parameters

    Parameter

    Type

    Description

    metrics

    Array of objects

    Specifies the list of metric objects.

    For details, see Table 4.

    meta_data

    Object

    Specifies the metadata of query results, including the pagination information.

    For details, see Table 6.

    Table 4 metrics field data structure description

    Parameter

    Type

    Description

    namespace

    String

    Specifies the metric namespace.

    dimensions

    Array of objects

    Specifies the list of metric dimensions.

    For details, see Table 5.

    metric_name

    String

    Specifies the metric name, such as cpu_util.

    unit

    String

    Specifies the metric unit.

    Table 5 dimensions field data structure description

    Parameter

    Type

    Description

    name

    String

    Specifies the dimension. For example, the ECS dimension is instance_id. For details, see the key field in Dimension.

    value

    String

    Specifies the dimension value, for example, an ECS ID.

    The value is a string of 1 to 256 characters.

    Table 6 meta_data field data structure description

    Parameter

    Type

    Description

    count

    Integer

    Specifies the number of returned results.

    marker

    String

    Specifies the pagination marker.

    For example, you have queried 10 records this time and the tenth record is about cpu_util. In your next query, if start is set to cpu_util, you can start your query from the next metric of cpu_util.

    total

    Integer

    Specifies the total number of metrics.

  • Example response
    {
        "metrics": [
            {
                "namespace": "SYS.ECS", 
                "dimensions": [
                    {
                        "name": "instance_id", 
                        "value": "d9112af5-6913-4f3b-bd0a-3f96711e004d"
                    }
                ], 
                "metric_name": "cpu_util", 
                "unit": "%"
            }
        ], 
        "meta_data": {
            "count": 1, 
            "marker": "SYS.ECS.cpu_util.instance_id:d9112af5-6913-4f3b-bd0a-3f96711e004d", 
            "total": 7
        }
    }

Returned Values

  • Normal

    200

  • Abnormal

    Returned Values

    Description

    400 Bad Request

    Request error.

    401 Unauthorized

    The authentication information is not provided or is incorrect.

    403 Forbidden

    You are forbidden to access the page requested.

    408 Request Timeout

    The request timed out.

    429 Too Many Requests

    Concurrent requests are excessive.

    500 Internal Server Error

    Failed to complete the request because of an internal service error.

    503 Service Unavailable

    The service is currently unavailable.

Error Code

For details, see Error Codes.