This topic describes how to report monitoring data for custom events by using the SDK for Java.

Install the SDK for Java

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

Sample code

The following sample code shows how to report event monitoring data by using the 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 An endpoint is the access address of a cloud service. The endpoints of Cloud Monitor are in the format of For more information about the endpoints of Cloud Monitor in different regions, see Endpoint.

Sample response

The following code shows the sample response that is returned when you report event monitoring data by using the SDK for Java:
    "Message": "success",
    "RequestId": "E25EE651-9C97-4EFD-AF22-A753B674E8D4",
    "Code": "200"

The HTTP status code 200 indicates a success.