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;
}
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);
}
}
}
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;
}
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;
}
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;
}
Aggregations