Updated on 2025-09-09 GMT+08:00

Querying Metrics

Function

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

After a cloud service resource is deleted, its data is cached for 3 hours, so metrics of the resource can still be queried within the 3 hours.

Debugging

You can debug the API in API Explorer which supports automatic authentication. API Explorer can automatically generate and debug example SDK code.

URI

GET /V1.0/{project_id}/metrics

  • Parameter description
    Table 1 Parameter description

    Parameter

    Mandatory

    Description

    project_id

    Yes

    Definition

    Project ID, which is used to specify the project that an asset belongs to. You can query the assets of a project by project ID. You can obtain the project ID from the API or console. For details about how to obtain the project ID, see Obtaining a Project ID.

    Constraints

    N/A

    Range

    1 to 64 characters

    Default Value

    N/A

    Table 2 Query parameter description

    Parameter

    Mandatory

    Type

    Description

    namespace

    No

    String

    Definition

    Service metric namespace. For details, see Services Interconnected with Cloud Eye.

    Constraints

    N/A

    Range

    The namespace must be in the service.item format. service and item must be strings, and each must start with a letter and contain only letters (case-insensitive), digits, and underscores (_). In addition, service cannot start with SYS, AGT, or SRE. namespace cannot be SERVICE.BMS because this namespace has been used by the system. The value can contain 3 to 32 characters. For example, the ECS namespace is SYS.ECS, and the DDS namespace is SYS.DDS.

    Default Value

    N/A

    metric_name

    No

    String

    Definition

    Metric ID. For example, metric_name of ECS CPU usage is cpu_util. For details about the metrics of each service, see Services Interconnected with Cloud Eye.

    Constraints

    N/A

    Range

    The value must start with a letter and can contain only digits, letters (case-insensitive), underscores (_), and hyphens (-). For example, the ECS metric cpu_util indicates the CPU usage of an ECS. The DDS metric mongo001_command_ps indicates the command execution frequency. The value can contain 1 to 96 characters.

    Default Value

    N/A

    dim

    No

    String

    Definition

    Dimension of a metric.

    Constraints

    N/A

    Range

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

    The following dimensions are only examples. For details about whether multiple dimensions are supported, see Services Interconnected with Cloud Eye.

    Single dimension: dim.0=instance_id,i-12345

    Multiple dimensions: dim.0=instance_id,i-12345&dim.1=instance_name,i-1234

    Default Value

    N/A

    start

    No

    String

    Definition

    Pagination start value.

    Constraints

    N/A

    Range

    The value is in the namespace.metric_name.key:value format.

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

    Default Value

    N/A

    limit

    No

    Integer

    Definition

    Maximum number of records that can be queried at a time.

    Constraints

    N/A

    Range

    [1, 1,000]

    Default Value

    1,000

    order

    No

    String

    Definition

    Result sorting method, which is sorted by timestamp.

    Constraints

    N/A

    Range

    The value can be:

    • asc: ascending order
    • desc: descending order

    Default Value

    asc

  • Example requests
    Example request 1: Query all metrics that can be monitored.
    GET https://{Cloud Eye endpoint}/V1.0/{project_id}/metrics
    Example request 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 Parameter description

    Parameter

    Type

    Description

    metrics

    Array of objects

    Definition

    List of metric objects.

    For details, see Table 4.

    meta_data

    Object

    Definition

    Metadata of query results, including the pagination information.

    For details, see Table 6.

    Table 4 metrics data structure description

    Parameter

    Type

    Description

    namespace

    String

    Definition

    Namespace of the metric.

    Range

    N/A

    dimensions

    Array of objects

    Definition

    List of metric dimensions.

    For details, see Table 5.

    metric_name

    String

    Definition

    Metric name, such as cpu_util.

    Range

    N/A

    unit

    String

    Definition

    Metric unit.

    Range

    N/A

    Table 5 dimensions data structure description

    Parameter

    Type

    Description

    name

    String

    Definition

    Monitoring dimension name. For example, the ECS dimension is instance_id. For details about the dimension of each service, see the key column in Services Interconnected with Cloud Eye.

    Range

    N/A

    value

    String

    Definition

    Dimension value, for example, an ECS ID.

    Range

    N/A

    Table 6 meta_data data structure description

    Parameter

    Type

    Description

    count

    Integer

    Definition

    Number of returned records.

    Range

    N/A

    marker

    String

    Definition

    Start of the next page, which is used for pagination.

    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.

    Range

    N/A

    total

    Integer

    Definition

    Total number of metrics.

    Range

    N/A

  • 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 Value

    Description

    400 Bad Request

    Request error.

    401 Unauthorized

    The authentication information is not provided or is incorrect.

    403 Forbidden

    Access to the requested page is forbidden.

    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 Codes

See Error Codes.