Search in sources :

Example 1 with MetricInfo

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

the class ITMetricSnippets method beforeClass.

@BeforeClass
public static void beforeClass() {
    RemoteLoggingHelper helper = RemoteLoggingHelper.create();
    logging = helper.getOptions().getService();
    MetricInfo metricInfo = MetricInfo.newBuilder(METRIC_NAME, METRIC_FILTER).setDescription(DESCRIPTION).build();
    metricSnippets = new MetricSnippets(logging.create(metricInfo));
}
Also used : RemoteLoggingHelper(com.google.cloud.logging.testing.RemoteLoggingHelper) MetricInfo(com.google.cloud.logging.MetricInfo) BeforeClass(org.junit.BeforeClass)

Example 2 with MetricInfo

use of com.google.cloud.logging.MetricInfo 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 MetricInfo

use of com.google.cloud.logging.MetricInfo 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 4 with MetricInfo

use of com.google.cloud.logging.MetricInfo 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 5 with MetricInfo

use of com.google.cloud.logging.MetricInfo 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)

Aggregations

MetricInfo (com.google.cloud.logging.MetricInfo)6 Metric (com.google.cloud.logging.Metric)5 Logging (com.google.cloud.logging.Logging)1 RemoteLoggingHelper (com.google.cloud.logging.testing.RemoteLoggingHelper)1 BeforeClass (org.junit.BeforeClass)1