This topic describes how to report monitoring data by sending an HTTP request.

Endpoints

You can use the following endpoints to report custom events to CloudMonitor:
  • Public endpoint: You can use the public endpoint to report custom events over the Internet.

    Public endpoint: http://metrichub-cms-cn-hangzhou.aliyuncs.com.

  • Virtual private cloud (VPC) endpoints: You can use the endpoints of this type to report custom events from VPCs in the region where CloudMonitor is used. You do not need to allow access to CloudMonitor from the Internet.
    The following table describes the VPC endpoints in different regions.
    Region name Region ID Endpoint
    China (Hangzhou) cn-hangzhou http://metrichub-cn-hangzhou.aliyun.com
    China (Shanghai) cn-shanghai http://metrichub-cn-shanghai.aliyun.com
    China (Qingdao) cn-qingdao http://metrichub-cn-qingdao.aliyun.com
    China (Beijing) cn-beijing http://metrichub-cn-beijing.aliyun.com
    China (Zhangjiakou) cn-zhangjiakou http://metrichub-cn-zhangjiakou.aliyun.com
    China (Hohhot) cn-huhehaote http://metrichub-cn-huhehaote.aliyun.com
    China (Shenzhen) cn-shenzhen http://metrichub-cn-shenzhen.aliyun.com
    China (Hong Kong) cn-hongkong http://metrichub-cn-hongkong.aliyun.com
    UAE (Dubai) me-east-1 http://metrichub-me-east-1.aliyun.com
    US (Silicon Valley) us-west-1 http://metrichub-us-west-1.aliyun.com
    US (Virginia) us-east-1 http://metrichub-us-east-1.aliyun.com
    Japan (Tokyo) ap-northeast-1 http://metrichub-ap-northeast-1.aliyun.com
    Germany (Frankfurt) eu-central-1 http://metrichub-eu-central-1.aliyun.com
    Australia (Sydney) ap-southeast-2 http://metrichub-ap-southeast-2.aliyun.com
    Singapore (Singapore) ap-southeast-1 http://metrichub-ap-southeast-1.aliyun.com
    Malaysia (Kuala Lumpur) ap-southeast-3 http://metrichub-ap-southeast-3.aliyun.com
    India (Mumbai) ap-south-1 http://metrichub-ap-south-1.aliyuncs.com
    South Korea (Seoul) ap-northeast-2 http://metrichub-ap-northeast-2.aliyuncs.com
    Thailand (Bangkok) ap-southeast-7 http://metrichub-ap-southeast-7.aliyuncs.com

Request syntax

An HTTP request uses the following syntax to report monitoring data:
POST /metric/custom/upload HTTP/1.1 
Authorization:<AuthorizationString>
Content-Length:<Content Length>
Content-MD5:<Content MD5>
Content-Type:application/json
Date:<GMT Date>
Host: metrichub-cms-cn-hangzhou.aliyuncs.com
x-cms-signature:hmac-sha1
x-cms-api-version:1.0
x-cms-ip:192.168.XX.XX
User-Agent:cms-java-sdk-v-1.0
[{"dimensions":{"key":"value"},"groupId":12345,"metricName":"TestMetric","period":60,"time":"20210827T143329.213+0800","type":0,"values":{"value":10}}]

Request headers and parameters

The following tables describe the headers and parameters in an HTTP request for reporting monitoring data.
  • Request headers
    Header Type Description Example
    Authorization String The authorization string that is in the format of AccessKeyID:SignString. testKey:F86ADF652A6466FCCD860B867D9518D48C24E7F6
    Content-Length Long The body length of the HTTP request that is defined in RFC 2616. The request body is measured by the number of bytes encoded in UTF-8.
    Note This header is required only if the request has a body.
    151
    Content-MD5 String The MD5 hash of the HTTP request body. The MD5 hash is a string that consists of uppercase letters and digits.
    Note This header is required only if the request has a body.
    215614AA47799058C009D3E20B19B83A
    Content-Type String The type of the content that is sent in the HTTP request. Set the value to application/json. application/json
    Date String The standard timestamp header of the HTTP request. This timestamp header follows the time format defined in RFC 1123 and uses the UTC standard time.

    Example: Mon, 3 Jan 2010 08:33:47 UTC.

    Fri, 27 Aug 2021 06:33:55 GMT
    Host String The full hostname of the HTTP request. This header does not include protocol headers such as https://.

    Example: metrichub-cms-cn-hangzhou.aliyuncs.com.

    metrichub-cms-cn-hangzhou.aliyuncs.com
    x-cms-api-version String The version of the API. Set the value to 1.0. 1.0
    x-cms-signature String The signature algorithm. CloudMonitor supports the HMAC-SHA1 signature algorithm. hmac-sha1
    x-cms-ip String The IP address of the host that reports the monitoring data. 192.168.XX.XX
    User-Agent String The description of the client. cms-java-sdk-v-1.0
  • Request parameters
    Parameter Type Required Description
    groupId Long Yes The ID of the application group.
    metricName String Yes The name of the metric. For more information, see Appendix 1: Metrics.
    dimensions Object Yes The dimensions that specify the resources whose monitoring data you want to query.

    The value is a collection of key-value pairs. A typical pair is instanceId:i-abcdefgh12****.

    time String Yes The timestamp when the metric is generated. Valid values:
    • yyyyMMdd'T'HHmmss.SSSZ

      Example: 20171012T132456.888+0800

    • long

      Example: 1508136760000

    type Int Yes

    The type of the reported data. Valid values: 0 and 1. A value of 0 indicates raw data and a value of 1 indicates aggregate data.

    We recommend that you report aggregate data in both the aggregation periods of 60s and 300s. Otherwise, you cannot query monitoring data in a time span that is more than seven days.

    period String No

    The aggregation period. Unit: seconds.

    If the type parameter is set to 1, the period parameter is required. Valid values:
    • 60
    • 300
    values Object Yes The collection of metric values.

    If the type parameter is set to 0, the keys in this parameter must be set to the specified value. CloudMonitor aggregates raw data in each aggregation period to generate multiple statistical values, such as the maximum value, the count, and the total value.

Sample response

The following code shows the sample response to an HTTP request that reports monitoring data:

{
  "code":"200",// The HTTP status code 200 indicates that the request was successful. 
  "msg":""// The value is empty if the monitoring data is reported. 
}