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

Querying Monitoring Data

Function

This API is used to query the monitoring data at a specified granularity for a specified metric in a specified period of time. You can specify the dimension of data to be queried.

URI

GET /V1.0/{project_id}/metric-data?namespace={namespace}&metric_name={metric_name}&dim.{i}=key,value&from={from}&to={to}&period={period}&filter={filter}

  • 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

    Yes

    String

    Specifies 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

    Yes

    String

    Specifies the metric name. You can obtain the metric names of existing alarm rules by referring to Querying the Metric List.

    from

    Yes

    String

    Specifies the start time of the query.

    The value is a UNIX timestamp and the unit is ms.

    Set the value of from to at least one period earlier than the current time.

    Rollup aggregates the raw data generated within a period to the start time of the period. Therefore, if values of from and to are within a period, the query result will be empty due to the rollup failure.

    Take the 5-minute period as an example. If it is 10:35 now, the raw data generated between 10:30 and 10:35 will be aggregated to 10:30. Therefore, in this example, if the value of period is 5 minutes, the value of from should be 10:30 or earlier.

    NOTE:

    Cloud Eye rounds up the value of from based on the level of granularity required to perform the rollup.

    to

    Yes

    String

    Specifies the end time of the query.

    The value is a UNIX timestamp and the unit is ms.

    The value of parameter from must be earlier than that of parameter to.

    period

    Yes

    Integer

    Specifies how often Cloud Eye aggregates data.

    Possible values are:

    • 1: Cloud Eye performs no aggregation and displays raw data.
    • 300: Cloud Eye aggregates data every 5 minutes.
    • 1200: Cloud Eye aggregates data every 20 minutes.
    • 3600: Cloud Eye aggregates data every 1 hour.
    • 14400: Cloud Eye aggregates data every 4 hours.
    • 86400: Cloud Eye aggregates data every 24 hours.

    filter

    Yes

    String

    Specifies the data rollup method. The following methods are supported:

    • average: Cloud Eye calculates the average value of metric data within a rollup period.
    • max: Cloud Eye calculates the maximum value of metric data within a rollup period.
    • min: Cloud Eye calculates the minimum value of metric data within a rollup period.
    • sum: Cloud Eye calculates the sum of metric data within a rollup period.
    • variance: Cloud Eye calculates the variance value of metric data within a rollup period.
    NOTE:

    Rollup uses a rollup method to aggregate raw data generated within a specific period. Take the 5-minute period as an example. If it is 10:35 now, the raw data generated between 10:30 and 10:35 will be aggregated to 10:30.

    dim

    Yes

    String

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

    The following dimensions are only examples. For details about dimensions of each service, see the description of each service, for example, instance_id of the ECS in Dimension.

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

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

  • Example:

    Request example 1: View the CPU usage of ECS whose ID is 6f3c6f91-4b24-4e1b-b7d1-a94ac1cb011d from 2019-04-30 20:00:00 to 2019-04-30 22:00:00. The monitoring interval is 20 minutes.

    GET https://{Cloud Eye endpoint}/V1.0/{project_id}/metric-data?namespace=SYS.ECS&metric_name=cpu_util&dim.0=instance_id,6f3c6f91-4b24-4e1b-b7d1-a94ac1cb011d&from=1556625600000&to=1556632800000&period=1200&filter=min

Request

None

Response

  • Response parameters
    Table 3 Response parameters

    Parameter

    Type

    Description

    datapoints

    Array of objects

    Specifies the metric data list. For details, see Table 4.

    Since Cloud Eye rounds up the value of from based on the level of granularity for data query, datapoints may contain more data points than expected.

    metric_name

    String

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

    Table 4 datapoints field data structure description

    Parameter

    Type

    Description

    average

    double

    Specifies the metric value. The value of this parameter is the same as that of parameter filter. The value can be max/min/average/sum/variance.

    timestamp

    long

    Specifies the time when the metric is collected. It is a UNIX timestamp in milliseconds.

    unit

    String

    Specifies the metric unit.

  • Example response
    {
        "datapoints": [
            {
                "average": 0, 
                "timestamp": 1442341200000, 
                "unit": "Count"
            }
        ], 
        "metric_name": "cpu_util"
    }

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.