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