You can report custom monitoring data to Cloud Monitor by using Alibaba Cloud CLI.
Grant permissions on Cloud Monitor to a RAM user
You can use an Alibaba Cloud account or a Resource Access Management (RAM) user to report monitoring data. If a RAM user uses an AccessKey pair to report monitoring data, grant Cloud Monitor permissions to the RAM user:
- Log on to the RAM console with an 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.
- Attach the AliyunCloudMonitorFullAccess policy to the RAM user.
For more information, see Manage RAM user permissions.
Install and configure Alibaba Cloud CLI
For more information, see Install Alibaba Cloud CLI in Windows or Install Alibaba Cloud CLI in Linux.
Report monitoring data
Call the PutCustomMetric operation to report monitoring data. For more information, see PutCustomMetric.
Sample command:
aliyun cms PutCustomMetric --MetricList.1.MetricName cpu_total --MetricList.1.Dimensions '{"sampleName1":"value1","sampleName2":"value2"}' --MetricList.1.Time 1555390981421 --MetricList.1.Type 0 --MetricList.1.Period 60 --MetricList.1.Values '{"value":10.5}' --MetricList.1.GroupId "0"
A status code 200 indicates that the monitoring data is reported.
{
"Message": "success",
"RequestId": "F69F5623-DDD6-42AE-AE59-87A2B841620B",
"Code": "200"
}
Status codes
The following table lists the status codes that Cloud Monitor may return when you report monitoring data.
| Status code | Description |
| 200 | The monitoring data is reported. |
| 206 |
|
| 400 | The request contains a syntax error. |
| 403 | Verification failed, the rate reached the throttling threshold, or the required permission is missing. |
| 500 | An internal server error occurred. |