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.
-
Log on to the RAM console with your Alibaba Cloud account.
-
Create a RAM user.
For more information, see Create a RAM user.
-
Create an AccessKey pair for the RAM user.
For more information, see Create an AccessKey.
ImportantSave the AccessKey pair. The AccessKey pair is required when you configure Alibaba Cloud CLI.
-
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.
-
Install Alibaba Cloud CLI.
For more information, see Install Alibaba Cloud CLI on Windows.
-
Configure Alibaba Cloud CLI.
For more information, see Configure a credential of the AccessKey type.
ImportantThe 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
-
Report the monitoring data of a custom event.
Sample code:
aliyun cms PutCustomEvent --EventInfo.1.EventName ErrorEvent --EventInfo.1.Content helloworldNoteFor 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.
-
View the reported monitoring data of the custom event in the Cloud Monitor console.
For more information, see View custom events.