Search in sources :

Example 1 with Metric

use of com.google.cloud.logging.Metric in project google-cloud-java by GoogleCloudPlatform.

the class ITLoggingSnippets method testMetric.

@Test
public void testMetric() throws ExecutionException, InterruptedException {
    String metricName1 = RemoteLoggingHelper.formatForTest("metric_name1");
    String metricName2 = RemoteLoggingHelper.formatForTest("metric_name2");
    Metric metric1 = loggingSnippets.createMetric(metricName1);
    Metric metric2 = loggingSnippets.createMetricAsync(metricName2);
    assertNotNull(metric1);
    assertNotNull(metric2);
    metric1 = loggingSnippets.getMetric(metricName1);
    metric2 = loggingSnippets.getMetricAsync(metricName2);
    assertNotNull(metric1);
    assertNotNull(metric2);
    metric1 = loggingSnippets.updateMetric(metricName1);
    metric2 = loggingSnippets.updateMetricAsync(metricName2);
    Set<Metric> metrics = Sets.newHashSet(loggingSnippets.listMetrics().iterateAll());
    while (!metrics.contains(metric1) || !metrics.contains(metric2)) {
        Thread.sleep(500);
        metrics = Sets.newHashSet(loggingSnippets.listMetrics().iterateAll());
    }
    metrics = Sets.newHashSet(loggingSnippets.listMetricsAsync().iterateAll());
    while (!metrics.contains(metric1) || !metrics.contains(metric2)) {
        Thread.sleep(500);
        metrics = Sets.newHashSet(loggingSnippets.listMetricsAsync().iterateAll());
    }
    assertTrue(loggingSnippets.deleteMetric(metricName1));
    assertTrue(loggingSnippets.deleteMetricAsync(metricName2));
}
Also used : Metric(com.google.cloud.logging.Metric) Test(org.junit.Test)

Example 2 with Metric

use of com.google.cloud.logging.Metric in project google-cloud-java by GoogleCloudPlatform.

the class LoggingSnippets method createMetric.

/**
   * Example of creating a metric for logs with severity higher or equal to ERROR.
   */
// [TARGET create(MetricInfo)]
// [VARIABLE "my_metric_name"]
public Metric createMetric(String metricName) {
    // [START createMetric]
    MetricInfo metricInfo = MetricInfo.of(metricName, "severity>=ERROR");
    Metric metric = logging.create(metricInfo);
    // [END createMetric]
    return metric;
}
Also used : MetricInfo(com.google.cloud.logging.MetricInfo) Metric(com.google.cloud.logging.Metric)

Example 3 with Metric

use of com.google.cloud.logging.Metric in project google-cloud-java by GoogleCloudPlatform.

the class MetricSnippets method updateAsync.

/**
   * Example of asynchronously updating the metric's information.
   */
// [TARGET updateAsync()]
public Metric updateAsync() throws ExecutionException, InterruptedException {
    // [START updateAsync]
    Future<Metric> future = metric.toBuilder().setDescription("A more detailed description").build().updateAsync();
    // ...
    Metric updatedMetric = future.get();
    // [END updateAsync]
    return updatedMetric;
}
Also used : Metric(com.google.cloud.logging.Metric)

Example 4 with Metric

use of com.google.cloud.logging.Metric in project google-cloud-java by GoogleCloudPlatform.

the class MetricSnippets method reloadAsync.

/**
   * Example of asynchronously getting the metric's latest information.
   */
// [TARGET reloadAsync()]
public Metric reloadAsync() throws ExecutionException, InterruptedException {
    // [START reloadAsync]
    Future<Metric> future = metric.reloadAsync();
    // ...
    Metric latestMetric = future.get();
    if (latestMetric == null) {
    // the metric was not found
    }
    // [END reloadAsync]
    return latestMetric;
}
Also used : Metric(com.google.cloud.logging.Metric)

Example 5 with Metric

use of com.google.cloud.logging.Metric in project google-cloud-java by GoogleCloudPlatform.

the class LoggingSnippets method getMetricAsync.

/**
   * Example of asynchronously getting a metric.
   */
// [TARGET getMetricAsync(String)]
// [VARIABLE "my_metric_name"]
public Metric getMetricAsync(String metricName) throws ExecutionException, InterruptedException {
    // [START getMetricAsync]
    Future<Metric> future = logging.getMetricAsync(metricName);
    // ...
    Metric metric = future.get();
    if (metric == null) {
    // metric was not found
    }
    // [END getMetricAsync]
    return metric;
}
Also used : Metric(com.google.cloud.logging.Metric)

Aggregations

Metric (com.google.cloud.logging.Metric)11 MetricInfo (com.google.cloud.logging.MetricInfo)5 Test (org.junit.Test)2 AsyncPage (com.google.api.gax.paging.AsyncPage)1 Logging (com.google.cloud.logging.Logging)1