use of com.google.cloud.monitoring.v3.MetricServiceClient.ListMetricDescriptorsPagedResponse in project java-docs-samples by GoogleCloudPlatform.
the class Snippets method listMetricDescriptors.
/**
* Returns the first page of all metric descriptors.
*/
void listMetricDescriptors() throws IOException {
// [START monitoring_list_descriptors]
// Your Google Cloud Platform project ID
String projectId = System.getProperty("projectId");
final MetricServiceClient client = MetricServiceClient.create();
ProjectName name = ProjectName.of(projectId);
ListMetricDescriptorsRequest request = ListMetricDescriptorsRequest.newBuilder().setName(name.toString()).build();
ListMetricDescriptorsPagedResponse response = client.listMetricDescriptors(request);
System.out.println("Listing descriptors: ");
for (MetricDescriptor d : response.iterateAll()) {
System.out.println(d.getName() + " " + d.getDisplayName());
}
// [END monitoring_list_descriptors]
}
use of com.google.cloud.monitoring.v3.MetricServiceClient.ListMetricDescriptorsPagedResponse in project java-docs-samples by GoogleCloudPlatform.
the class BigQueryRunner method createMetricsIfNeeded.
// [END bigquery_logging_list_time_series]
// [START bigquery_logging_list_and_create_metrics]
private void createMetricsIfNeeded() {
// If all required metrics already exist, no need to make service calls.
if (REQUIRED_METRICS.stream().map(MetricDescriptor::getDisplayName).allMatch(existingMetrics::contains)) {
return;
}
ListMetricDescriptorsRequest listMetricsRequest = ListMetricDescriptorsRequest.newBuilder().setName(projectName).setFilter(CUSTOM_METRIC_FILTER).build();
ListMetricDescriptorsPagedResponse listMetricsResponse = client.listMetricDescriptors(listMetricsRequest);
for (MetricDescriptor existingMetric : listMetricsResponse.iterateAll()) {
existingMetrics.add(existingMetric.getDisplayName());
}
REQUIRED_METRICS.stream().filter(metric -> !existingMetrics.contains(metric.getDisplayName())).forEach(this::createMetric);
}
Aggregations