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

Adding Monitoring Data

Function

This API is used to add one or more pieces of custom metric monitoring data to solve the problem that the system metrics cannot meet specific service requirements.

URI

POST /V1.0/{project_id}/metric-data

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

Request

  1. The size of a POST request cannot exceed 512 KB. Otherwise, the request will be denied.
  2. The period for sending POST requests must be shorter than the minimum aggregation period. Otherwise, the aggregated data will be noncontinuous. For example, if the aggregation period is 5 minutes and the POST request sending period is 7 minutes, the data will be aggregated every 10 minutes, rather than 5 minutes.
  3. Timestamp (collect_time) in the POST request body value must be within the period that starts from three days before the current time to 10 minutes after the current time. If it is not in this range, you are not allowed to insert the metric data.
  • Request parameters
    Table 2 Parameter description

    Parameter

    Type

    Mandatory

    Description

    Array elements

    Array of objects

    Yes

    Specifies whether to add one or more pieces of custom metric monitoring data.

    Table 3 Array elements

    Parameter

    Mandatory

    Type

    Description

    metric

    Yes

    Object

    Specifies the metric data.

    For details, see Table 4.

    ttl

    Yes

    Integer

    Specifies the data validity period. The unit is second. The value range is 0–604,800 seconds. If the validity period expires, the data will be automatically deleted.

    collect_time

    Yes

    long

    Specifies the time when the data was collected.

    The time is UNIX timestamp (ms) format.

    NOTE:

    Since there is a latency between the client and the server, the data timestamp to be inserted should be within the period that starts from three days before the current time plus 20s to 10 minutes after the current time minus 20s. In this way, the timestamp will be inserted to the database without being affected by the latency.

    value

    Yes

    double

    Specifies the monitoring metric data to be added.

    The value can be an integer or a floating point number.

    unit

    No

    String

    Specifies the data unit.

    Enter a maximum of 32 characters.

    type

    No

    String

    Specifies the enumerated type.

    Valid value:

    • int
    • float
    Table 4 metric field data structure description

    Parameter

    Mandatory

    Type

    Description

    namespace

    Yes

    String

    Specifies the customized namespace. For example, see Namespace for the customized 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 (_). In addition, service cannot start with SYS and AGT, and namespace cannot be SERVICE.BMS because this namespace has been used by the system.

    This parameter can be left blank when alarm_type is set to (EVENT.SYS| EVENT.CUSTOM).

    dimensions

    Yes

    Array of objects

    Specifies the metric dimension. A maximum of three dimensions are supported.

    For details, see Table 5.

    metric_name

    Yes

    String

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

    Table 5 dimensions field data structure description

    Parameter

    Mandatory

    Type

    Description

    name

    No

    String

    Specifies the dimension. For example, the ECS dimension is instance_id, which is listed in the key column in Dimension.

    The value can be a string of 1 to 32 characters and must start with a letter and contain only uppercase letters, lowercase letters, digits, underscores (_), and hyphens (-).

    value

    No

    String

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

    The value can be a string of 1 to 256 characters and must start with a letter or a digit and contain only uppercase letters, lowercase letters, digits, underscores (_), and hyphens (-).

  • Example request
    [
        {
            "metric": {
                "namespace": "MINE.APP",
                "dimensions": [
                    {
                        "name": "instance_id",
                        "value": "33328f02-3814-422e-b688-bfdba93d4050"
                    }
                ],
                "metric_name": "cpu_util"
            },
            "ttl": 172800,
            "collect_time": 1463598260000,
            "type": "int",
            "value": 60,
            "unit": "%"
        },
        {
            "metric": {
                "namespace": "MINE.APP",
                "dimensions": [
                    {
                        "name": "instance_id",
                        "value": "33328f02-3814-422e-b688-bfdba93d4050"
                    }
                ],
                "metric_name": "cpu_util"
            },
            "ttl": 172800,
            "collect_time": 1463598270000,
            "type": "int",
            "value": 70,
            "unit": "%"
        }
    ]

Response

The response has no message body.

Returned Values

  • Normal

    201

  • Abnormal

    Returned Value

    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.