Search in sources :

Example 1 with MetricsStartEndListOptions

use of com.arm.mbed.cloud.sdk.connect.model.MetricsStartEndListOptions in project mbed-cloud-sdk-java by ARMmbed.

the class Connect method listMetrics.

/**
 * Lists metrics.
 * <p>
 * Example:
 *
 * <pre>
 * {@code
 * try {
 *     Calendar startDate = GregorianCalendar(2017,10,30,10,20,56);
 *     Calendar endDate = GregorianCalendar(2017,11,31,10,20,56);
 *
 *     MetricsStartEndListOptions listOptions = new MetricsStartEndListOptions();
 *     listOptions.setStart(startDate.getTime());
 *     listOptions.setEnd(endDate.getTime());
 *     listOptions.setInterval(new TimePeriod(360)); //Once an hour
 *
 *     ListResponse<Metric> metrics = connectApi.listMetrics(listOptions);
 *     //Iterates over a page
 *     for (Metric metric : metrics.getData()) {
 *         System.out.println("Time: " + dateFormat.format(metric.getTimestamp()));
 *         System.out.println("Successful bootstraps: " + metric.getSuccessfulBootstraps());
 *         System.out.println("Successful api calls: " + metric.getSuccessfulApiCalls());
 *         System.out.println("");
 *     }
 * } catch (MbedCloudException e) {
 *     e.printStackTrace();
 * }
 * }
 * </pre>
 *
 * @param options
 *            metrics options.
 * @param <T>
 *            Type of metrics list options
 * @return list of metrics for the corresponding options.
 * @throws MbedCloudException
 *             if a problem occurred during request processing.
 */
@API
@Nullable
public <T extends AbstractMetricsListOptions> ListResponse<Metric> listMetrics(@NonNull T options) throws MbedCloudException {
    checkNotNull(options, TAG_METRIC_OPTIONS);
    final T finalOptions = options;
    final Date finalStart = options instanceof MetricsStartEndListOptions ? ((MetricsStartEndListOptions) options).getStart() : null;
    final Date finalEnd = options instanceof MetricsStartEndListOptions ? ((MetricsStartEndListOptions) options).getEnd() : null;
    final String finalPeriod = options instanceof MetricsPeriodListOptions ? ((MetricsPeriodListOptions) options).getPeriod().toString() : null;
    return CloudCaller.call(this, "listMetrics()", MetricAdapter.getListMapper(), new CloudCall<SuccessfulResponse>() {

        @Override
        public Call<SuccessfulResponse> call() {
            return endpoint.getStatistic().v3MetricsGet(MetricAdapter.mapIncludes(finalOptions.getInclude()), finalOptions.getInterval().toString(), TranslationUtils.toLocalDate(finalStart), TranslationUtils.toLocalDate(finalEnd), finalPeriod, finalOptions.getLimit(), finalOptions.getAfter(), finalOptions.getOrder().toString());
        }
    });
}
Also used : SuccessfulResponse(com.arm.mbed.cloud.sdk.internal.statistics.model.SuccessfulResponse) Call(retrofit2.Call) CloudCall(com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall) MetricsPeriodListOptions(com.arm.mbed.cloud.sdk.connect.model.MetricsPeriodListOptions) MetricsStartEndListOptions(com.arm.mbed.cloud.sdk.connect.model.MetricsStartEndListOptions) Date(java.util.Date) API(com.arm.mbed.cloud.sdk.annotations.API) Nullable(com.arm.mbed.cloud.sdk.annotations.Nullable)

Example 2 with MetricsStartEndListOptions

use of com.arm.mbed.cloud.sdk.connect.model.MetricsStartEndListOptions in project mbed-cloud-sdk-java by ARMmbed.

the class ConnectExamples method listMarch2017Metric.

/**
 * Lists metrics for March 2017.
 */
@Example
public void listMarch2017Metric() {
    ConnectionOptions config = Configuration.get();
    Connect api = new Connect(config);
    try {
        // Defining query options.
        MetricsStartEndListOptions options = new MetricsStartEndListOptions();
        options.setStart(new GregorianCalendar(2017, 2, 1).getTime());
        options.setEnd(new GregorianCalendar(2017, 3, 1).getTime());
        // Listing metrics data.
        Paginator<Metric> metrics = api.listAllMetrics(options);
        for (Metric metric : metrics) {
            log("Metric", metric);
        }
    } catch (Exception e) {
        logError("last API Metadata", api.getLastApiMetadata());
        fail(e.getMessage());
    }
}
Also used : Connect(com.arm.mbed.cloud.sdk.Connect) MetricsStartEndListOptions(com.arm.mbed.cloud.sdk.connect.model.MetricsStartEndListOptions) GregorianCalendar(java.util.GregorianCalendar) ConnectionOptions(com.arm.mbed.cloud.sdk.common.ConnectionOptions) Metric(com.arm.mbed.cloud.sdk.connect.model.Metric) MbedCloudException(com.arm.mbed.cloud.sdk.common.MbedCloudException) AbstractExample(utils.AbstractExample) Example(utils.Example)

Example 3 with MetricsStartEndListOptions

use of com.arm.mbed.cloud.sdk.connect.model.MetricsStartEndListOptions in project mbed-cloud-sdk-java by ARMmbed.

the class TestAllListOptions method testMetricStartEndListOptionsClone.

@Test
public void testMetricStartEndListOptionsClone() {
    MetricsStartEndListOptions opt1 = new MetricsStartEndListOptions();
    opt1.addEqualFilter("field1", Integer.valueOf(3));
    opt1.includeTotalCount();
    opt1.setLimit(Integer.valueOf(2));
    opt1.setInterval("1d");
    opt1.setStart(new GregorianCalendar(2017, 0, 9).getTime());
    opt1.setEnd(new GregorianCalendar(2018, 0, 9).getTime());
    MetricsStartEndListOptions opt2 = new MetricsStartEndListOptions();
    assertNotEquals(opt2, opt1);
    assertNotSame(opt2, opt1);
    opt2 = opt1.clone();
    assertEquals(opt2, opt1);
    assertNotSame(opt2, opt1);
}
Also used : MetricsStartEndListOptions(com.arm.mbed.cloud.sdk.connect.model.MetricsStartEndListOptions) GregorianCalendar(java.util.GregorianCalendar) Test(org.junit.Test)

Aggregations

MetricsStartEndListOptions (com.arm.mbed.cloud.sdk.connect.model.MetricsStartEndListOptions)3 GregorianCalendar (java.util.GregorianCalendar)2 Connect (com.arm.mbed.cloud.sdk.Connect)1 API (com.arm.mbed.cloud.sdk.annotations.API)1 Nullable (com.arm.mbed.cloud.sdk.annotations.Nullable)1 CloudCall (com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall)1 ConnectionOptions (com.arm.mbed.cloud.sdk.common.ConnectionOptions)1 MbedCloudException (com.arm.mbed.cloud.sdk.common.MbedCloudException)1 Metric (com.arm.mbed.cloud.sdk.connect.model.Metric)1 MetricsPeriodListOptions (com.arm.mbed.cloud.sdk.connect.model.MetricsPeriodListOptions)1 SuccessfulResponse (com.arm.mbed.cloud.sdk.internal.statistics.model.SuccessfulResponse)1 Date (java.util.Date)1 Test (org.junit.Test)1 Call (retrofit2.Call)1 AbstractExample (utils.AbstractExample)1 Example (utils.Example)1