Deliver Records Using SDK

The best way to get started with the Smart Trading Cloud Monitoring service is to compile and run the sample project provided with the SDK package. The package is available here. The SDK package helps you configure the Cloud Monitoring service to start sending logs, metrics, and event records from your applications to the Monitoring service.

To start working with the Smart Trading Cloud Monitoring service, you have to first create an account at https://auth.sandbox.kollab.link or use your existing account credentials and make sure you are subscribed to the Smart Trading Cloud Monitoring Service. To subscribe to the service, contact your account administrator.

The SDK package contains the following:

  • A Java-based client
  • A sample Java project that illustrates basic interaction with the Smart Trading Cloud Monitoring service

The primary class of the imported project is com.collablynk.monitoring.input.MonitoringServiceClient, and is located at the following directory: example/src/main/java/com/collablynk/monitoring/input/example/Main.java

A typical usage workflow is as follows:

Create a new instance of the MonitoringServiceClient class using the default constructor:

MonitoringServiceClient client = MonitoringServiceClient

.create()

.withCredentials(AuthProviderBuilder.OAuth2()

.user("username", "password"))

.build();

The parameters "username" and "password" in the example above are your Smart Trading account credentials. For more information about user authentication and application user authentication, see advanced configurations.

You can send logs, events, and metrics to the Cloud Monitoring service. The code fragment below shows you how to send logs:

MonitoringServiceClient client = MonitoringServiceClient.create().build();

SendResult res = client

.send()

.logs("my custom source",

new LogRecord()

.withMessage("some log message")

.withTimestamp(System.currentTimeMillis())

.withParameters(new Parameters()

.put("key", "value")

.put("key2", "value2")),

new LogRecord()

.withMessage("some log message 2")

.withTimestamp(System.currentTimeMillis())

.withParameters(new Parameters()

.put("key", "value3")

.put("key2", "value4")));

For more information on how to send logs, metrics, and events and on the required data formats, see Send Data.

The Cloud Monitoring service APIs use conventional HTTP response codes to indicate success and failure. When the process of sending data to the Cloud Monitoring service has successfully started, you receive the 200 response code. However, that does not mean that all records have been processed. The service processes large requests in parts on the server and writes the result of each handled part to a socket to prevent read timeout expiration. The accumulated result of processing the records is a JSON object that you can read using any JSON mapper. You can also read a JSON stream using a streaming API of your mapper to track the progress of the processing. When all the parts have been successfully processed, the service commits the request. This means that if a fatal error occurs in any one of the parts of the records, no records are added to the Cloud Monitoring service.

You can analyze the result in the following way:

System.out.println("processed:" + res.getResult().getProcessed())

System.out.println("success :" + res.getResult().getSuccsessfull())

System.out.println("errors :" + res.getResult().getErrors().size())

To verify errors that appeared during the processing, use the error fields of the SendResult.getResult()class:

PartProcessingResult result;

List<PartProcessingResult> partialResults;

where result contains a final aggregated result of the whole request, and partialResults contains the intermediate results received from the Cloud Monitoring service during the execution of the request.

PartProcessingResult contains two counters: processed and successful. If all the parts of the records have successful counters, the records are added to the service. You can verify the result of the processed parts in SendResult.getPartialResults().

For information on how to investigate errors, see Handle Exceptions.