本文為您介紹通過Java SDK上報自定義事件監控數據的配置方法。
安裝Java SDK
通過Maven安裝Java SDK,需要添加的依賴如下:
<dependency>
<groupId>com.aliyun.openservices</groupId>
<artifactId>aliyun-cms</artifactId>
<version>0.2.4</version>
</dependency>
代碼示例
通過Java SDK方式上報事件監控數據的代碼示例如下:
public void uploadEvent() throws CMSException, InterruptedException {
//初始化客戶端
CMSClient cmsClient = new CMSClient(endpoint, accKey, secret);
//構建2個事件上報
CustomEventUploadRequest request = CustomEventUploadRequest.builder()
.append(CustomEvent.builder()
.setContent("abc,123")
.setGroupId(101L)
.setName("Event001").build())
.append(CustomEvent.builder()
.setContent("abc,123")
.setGroupId(101L)
.setName("Event002").build())
.build();
CustomEventUploadResponse response = cmsClient.putCustomEvent(request);
List<CustomEvent> eventList = new ArrayList<CustomEvent>();
eventList.add(CustomEvent.builder()
.setContent("abcd,1234")
.setGroupId(101L)
.setName("Event001").build());
eventList.add(CustomEvent.builder()
.setContent("abcd,1234")
.setGroupId(101L)
.setName("Event002").build());
request = CustomEventUploadRequest.builder()
.setEventList(eventList).build();
response = cmsClient.putCustomEvent(request);
}
說明 endpoint是云服務的接入地址,云監控的接入地址為
metrics.aliyuncs.com
。云監控各地域的接入地址,請參見服務地址。
返回示例
通過Java SDK方式上報事件監控數據的代碼返回示例如下:
{
"Message": "success",
"RequestId": "E25EE651-9C97-4EFD-AF22-A753B674E8D4",
"Code": "200"
}
HTTP狀態碼返回200表示成功。