Report the monitoring data of custom events by using Alibaba Cloud CLI

更新时间:
复制 MD 格式

You can use Alibaba Cloud Command Line Interface (CLI) to report the monitoring data of custom events. In this example, a Resource Access Management (RAM) user is created by using an Alibaba Cloud account, and then the RAM user uses an AccessKey pair to report custom event data.

Step 1: Create a RAM user and grant the permissions to manage Cloud Monitor to the RAM user

Create a RAM user by using your Alibaba Cloud account, create an AccessKey pair for the RAM user, and attach the AliyunCloudMonitorFullAccess policy.

  1. Log on to the RAM console with your Alibaba Cloud account.

  2. Create a RAM user.

    For more information, see Create a RAM user.

  3. Create an AccessKey pair for the RAM user.

    For more information, see Create an AccessKey.

    Important

    Save the AccessKey pair. The AccessKey pair is required when you configure Alibaba Cloud CLI.

  4. Attach the AliyunCloudMonitorFullAccess policy to the RAM user.

    For more information, see Manage RAM user permissions.

Step 2: Install and configure Alibaba Cloud CLI

In this example, Alibaba Cloud CLI is installed and configured on Windows.

  1. Install Alibaba Cloud CLI.

    For more information, see Install Alibaba Cloud CLI on Windows.

  2. Configure Alibaba Cloud CLI.

    For more information, see Configure a credential of the AccessKey type.

    Important

    The AccessKey ID and AccessKey secret are the AccessKey pair created in Substep 3 of Step 1.

Step 3: Report the monitoring data of a custom event

  1. Report the monitoring data of a custom event.

    Sample code:

    aliyun cms PutCustomEvent --EventInfo.1.EventName ErrorEvent  --EventInfo.1.Content helloworld
    Note

    For more information about the request parameters of the PutCustomEvent operation, see PutCustomEvent.

    A status code of 200 indicates that the custom event data is reported.

    {
            "Code": "200",
            "Message": "success",
            "RequestId": "50958CD5-C81A-5747-9154-4AFC430E3541"
    }

    The following table lists the error codes.

    Error code

    Description

    400

    The request contains a syntax error.

    403

    Verification failed, the request was throttled, or the required permission is missing.

    500

    An internal server error occurred.

  2. View the reported monitoring data of the custom event in the Cloud Monitor console.

    For more information, see View custom events.