Search in sources :

Example 6 with Metric

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

the class LoggingSnippets method createMetricAsync.

/**
   * Example of asynchronously creating a metric for logs with severity higher or equal to ERROR.
   */
// [TARGET createAsync(MetricInfo)]
// [VARIABLE "my_metric_name"]
public Metric createMetricAsync(String metricName) throws ExecutionException, InterruptedException {
    // [START createMetricAsync]
    MetricInfo metricInfo = MetricInfo.of(metricName, "severity>=ERROR");
    Future<Metric> future = logging.createAsync(metricInfo);
    // ...
    Metric metric = future.get();
    // [END createMetricAsync]
    return metric;
}
Also used : MetricInfo(com.google.cloud.logging.MetricInfo) Metric(com.google.cloud.logging.Metric)

Example 7 with Metric

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

the class CreateAndListMetrics method main.

public static void main(String... args) throws Exception {
    // Credentials are inferred from the environment
    try (Logging logging = LoggingOptions.getDefaultInstance().getService()) {
        // Create a metric
        MetricInfo metricInfo = MetricInfo.newBuilder("test-metric", "severity >= ERROR").setDescription("Log entries with severity higher or equal to ERROR").build();
        logging.create(metricInfo);
        // List metrics
        Page<Metric> metrics = logging.listMetrics();
        for (Metric metric : metrics.iterateAll()) {
            System.out.println(metric);
        }
    }
}
Also used : Logging(com.google.cloud.logging.Logging) MetricInfo(com.google.cloud.logging.MetricInfo) Metric(com.google.cloud.logging.Metric)

Example 8 with Metric

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

the class LoggingSnippets method updateMetric.

/**
   * Example of updating a metric.
   */
// [TARGET update(MetricInfo)]
// [VARIABLE "my_metric_name"]
public Metric updateMetric(String metricName) {
    // [START updateMetric]
    MetricInfo metricInfo = MetricInfo.newBuilder(metricName, "severity>=ERROR").setDescription("new description").build();
    Metric metric = logging.update(metricInfo);
    // [END updateMetric]
    return metric;
}
Also used : MetricInfo(com.google.cloud.logging.MetricInfo) Metric(com.google.cloud.logging.Metric)

Example 9 with Metric

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

the class LoggingSnippets method listMetricsAsync.

/**
   * Example of asynchronously listing metrics, specifying the page size.
   */
// [TARGET listMetricsAsync(ListOption...)]
public Page<Metric> listMetricsAsync() throws ExecutionException, InterruptedException {
    // [START listMetricsAsync]
    Future<AsyncPage<Metric>> future = logging.listMetricsAsync(ListOption.pageSize(100));
    // ...
    AsyncPage<Metric> metrics = future.get();
    for (Metric metric : metrics.iterateAll()) {
    // do something with the metric
    }
    // [END listMetricsAsync]
    return metrics;
}
Also used : Metric(com.google.cloud.logging.Metric) AsyncPage(com.google.api.gax.paging.AsyncPage)

Example 10 with Metric

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

the class LoggingSnippets method updateMetricAsync.

/**
   * Example of asynchronously updating a metric.
   */
// [TARGET updateAsync(MetricInfo)]
// [VARIABLE "my_metric_name"]
public Metric updateMetricAsync(String metricName) throws ExecutionException, InterruptedException {
    // [START updateMetricAsync]
    MetricInfo metricInfo = MetricInfo.newBuilder(metricName, "severity>=ERROR").setDescription("new description").build();
    Future<Metric> future = logging.updateAsync(metricInfo);
    // ...
    Metric metric = future.get();
    // [END updateMetricAsync]
    return metric;
}
Also used : MetricInfo(com.google.cloud.logging.MetricInfo) 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