This topic describes how to report custom events by using Cloud Monitor SDK for Java.

Install Cloud Monitor SDK for Java

You can install Cloud Monitor SDK for Java by adding the following Maven dependency:

Sample code

The following sample code shows how to report custom events by using Cloud Monitor SDK for Java:
public void uploadEvent() throws CMSException, InterruptedException {
        // Initialize the client.
        CMSClient cmsClient = new CMSClient(endpoint, accKey, secret);
       // Construct two events to be reported.
         CustomEventUploadRequest request = CustomEventUploadRequest.builder()
            CustomEventUploadResponse response = cmsClient.putCustomEvent(request);
            List<CustomEvent> eventList = new ArrayList<CustomEvent>();
            request = CustomEventUploadRequest.builder()
            response = cmsClient.putCustomEvent(request);
Note The endpoint is used to access Cloud Monitor. The endpoint is in the format of For more information about Cloud Monitor endpoints in different regions, see Cloud Monitor endpoints.

Sample success responses

The following code shows the sample response that reports custom events by using SDK for Java:
    "Message": "success",
    "RequestId": "E25EE651-9C97-4EFD-AF22-A753B674E8D4",
    "Code": "200"

The HTTP status code 200 indicates that the custom events were reported.