Updated on 2022-12-05 GMT+08:00

Getting Started

Overview

This topic describes how to invoke a number of Cloud Eye APIs to create an alarm rule for the ECS CPU usage.

The validity period of a token obtained from IAM is 24 hours. If you want to use a token for authentication, cache it to avoid frequently calling the IAM API.

Procedure

  1. Obtain the user token.

    Send POST https://IAM endpoint/v3/auth/tokens.

    Add Content-Type:application/json to the request headers.

    The request body is as follows:

    {
      "auth": {
        "identity": {
          "methods": [
            "password"
          ],
          "password": {
            "user": {
              "name": "James",
              "password": "**********",
              "domain": {
                "name": "A-Company"
              }
            }
          }
        },
        "scope": {
          "project": {
            "name": "XXX",
            "domain": {
              "name": "A-Company"
            }
          }
        }
      }
    }

    Specify the following parameters:

    • user.name: username, which is set based on the obtained token body
    • password: login password
    • domain.name:: name of the account to which the user belongs. If the account is used to obtain the token, values of user.name of the account and domain.name are the same. In this case, enter the user.name value. Otherwise, enter the domain name to which the account belongs.
    • project.name: region

      Obtain X-Subject-Token from the response header, that is, the signed token.

  2. Query the list of metrics that can be monitored.

    Send GET https://Cloud Eye endpoint/V1.0/{project_id}/metrics.

    Add X-Auth-Token obtained in 1 to the request header.

    After the request is successfully responded, the metrics information is returned, such as "metric_name": "cpu_util" in the following figure.

    {
        "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
        }
    }

    If the request fails, an error code and error information are returned. For details, see Error Codes.

  3. Create an alarm rule.

    Send POST https://Cloud Eye endpoint/V1.0/{project_id}/alarms.

    Specify the following parameters in the request body:
    {
        "alarm_name": "alarm-rp0E",  //Alarm rule name (mandatory, string)
        "alarm_description": "", 
        "metric": {
            "namespace": "SYS.ECS",  //Namespace (mandatory, string)
            "dimensions": [
                {
                    "name": "instance_id", 
                    "value": "33328f02-3814-422e-b688-bfdba93d4051"
                }
            ], 
            "metric_name": "cpu_util"   //Metric name (mandatory, string)
        }, 
        "condition": {
            "period": 300,      //Monitoring period (mandatory, integer)
            "filter": "average",     //Data rollup method (mandatory, string)
            "comparison_operator": ">=",    //Operator of the alarm threshold (mandatory, string)
            "value": 80, //Threshold (mandatory, string)
            "unit": "%",  //Data unit (mandatory, string)
            "count": 1
        }, 
        "alarm_enabled": true, 
        "alarm_action_enabled": true, 
        "alarm_level": 2,
        "alarm_actions": [
            {
                "type": "notification", 
                "notificationList": [ ]
            }
        ], 
        "ok_actions": [
            {
                "type": "notification", 
                "notificationList": [ ]
            }
        ]
    }

    If the request is responded, the alarm rule ID is returned.

    {
        "alarm_id":"al1450321795427dR8p5mQBo"
    }

    If the request fails, an error code and error information are returned. For details, see Error Codes.

    You can query, enable, disable, or delete alarm rules based on the alarm rule ID obtained in 3.