Search in sources :

Example 1 with ListMetricDescriptorsRequest

use of com.google.monitoring.v3.ListMetricDescriptorsRequest in project google-cloud-java by GoogleCloudPlatform.

the class MetricServiceClientTest method listMetricDescriptorsTest.

@Test
@SuppressWarnings("all")
public void listMetricDescriptorsTest() {
    String nextPageToken = "";
    MetricDescriptor metricDescriptorsElement = MetricDescriptor.newBuilder().build();
    List<MetricDescriptor> metricDescriptors = Arrays.asList(metricDescriptorsElement);
    ListMetricDescriptorsResponse expectedResponse = ListMetricDescriptorsResponse.newBuilder().setNextPageToken(nextPageToken).addAllMetricDescriptors(metricDescriptors).build();
    mockMetricService.addResponse(expectedResponse);
    ProjectName name = ProjectName.create("[PROJECT]");
    ListMetricDescriptorsPagedResponse pagedListResponse = client.listMetricDescriptors(name);
    List<MetricDescriptor> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getMetricDescriptorsList().get(0), resources.get(0));
    List<GeneratedMessageV3> actualRequests = mockMetricService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListMetricDescriptorsRequest actualRequest = (ListMetricDescriptorsRequest) actualRequests.get(0);
    Assert.assertEquals(name, actualRequest.getNameAsProjectName());
}
Also used : MetricDescriptor(com.google.api.MetricDescriptor) ProjectName(com.google.monitoring.v3.ProjectName) ListMetricDescriptorsRequest(com.google.monitoring.v3.ListMetricDescriptorsRequest) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) ListMetricDescriptorsResponse(com.google.monitoring.v3.ListMetricDescriptorsResponse) ListMetricDescriptorsPagedResponse(com.google.cloud.monitoring.spi.v3.PagedResponseWrappers.ListMetricDescriptorsPagedResponse) Test(org.junit.Test)

Example 2 with ListMetricDescriptorsRequest

use of com.google.monitoring.v3.ListMetricDescriptorsRequest 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]
}
Also used : MetricDescriptor(com.google.api.MetricDescriptor) MetricServiceClient(com.google.cloud.monitoring.v3.MetricServiceClient) ProjectName(com.google.monitoring.v3.ProjectName) ListMetricDescriptorsRequest(com.google.monitoring.v3.ListMetricDescriptorsRequest) ListMetricDescriptorsPagedResponse(com.google.cloud.monitoring.v3.MetricServiceClient.ListMetricDescriptorsPagedResponse)

Example 3 with ListMetricDescriptorsRequest

use of com.google.monitoring.v3.ListMetricDescriptorsRequest 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);
}
Also used : ListTimeSeriesPagedResponse(com.google.cloud.monitoring.v3.MetricServiceClient.ListTimeSeriesPagedResponse) ListMetricDescriptorsRequest(com.google.monitoring.v3.ListMetricDescriptorsRequest) ListTimeSeriesRequest(com.google.monitoring.v3.ListTimeSeriesRequest) MetricDescriptor(com.google.api.MetricDescriptor) MetricServiceClient(com.google.cloud.monitoring.v3.MetricServiceClient) BigQuery(com.google.cloud.bigquery.BigQuery) ArrayList(java.util.ArrayList) BigQueryOptions(com.google.cloud.bigquery.BigQueryOptions) Lists(com.google.common.collect.Lists) ServiceOptions(com.google.cloud.ServiceOptions) TypedValue(com.google.monitoring.v3.TypedValue) Job(com.google.cloud.bigquery.Job) TableResult(com.google.cloud.bigquery.TableResult) Point(com.google.monitoring.v3.Point) PrintStream(java.io.PrintStream) ImmutableSet(com.google.common.collect.ImmutableSet) JobInfo(com.google.cloud.bigquery.JobInfo) ListMetricDescriptorsPagedResponse(com.google.cloud.monitoring.v3.MetricServiceClient.ListMetricDescriptorsPagedResponse) Metric(com.google.api.Metric) TimeSeries(com.google.monitoring.v3.TimeSeries) Set(java.util.Set) QueryJobConfiguration(com.google.cloud.bigquery.QueryJobConfiguration) Timestamps(com.google.protobuf.util.Timestamps) IOException(java.io.IOException) CreateTimeSeriesRequest(com.google.monitoring.v3.CreateTimeSeriesRequest) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) List(java.util.List) JobId(com.google.cloud.bigquery.JobId) CreateMetricDescriptorRequest(com.google.monitoring.v3.CreateMetricDescriptorRequest) TimeInterval(com.google.monitoring.v3.TimeInterval) MetricDescriptor(com.google.api.MetricDescriptor) ListMetricDescriptorsRequest(com.google.monitoring.v3.ListMetricDescriptorsRequest) ListMetricDescriptorsPagedResponse(com.google.cloud.monitoring.v3.MetricServiceClient.ListMetricDescriptorsPagedResponse)

Aggregations

MetricDescriptor (com.google.api.MetricDescriptor)3 ListMetricDescriptorsRequest (com.google.monitoring.v3.ListMetricDescriptorsRequest)3 MetricServiceClient (com.google.cloud.monitoring.v3.MetricServiceClient)2 ListMetricDescriptorsPagedResponse (com.google.cloud.monitoring.v3.MetricServiceClient.ListMetricDescriptorsPagedResponse)2 ProjectName (com.google.monitoring.v3.ProjectName)2 Metric (com.google.api.Metric)1 ServiceOptions (com.google.cloud.ServiceOptions)1 BigQuery (com.google.cloud.bigquery.BigQuery)1 BigQueryOptions (com.google.cloud.bigquery.BigQueryOptions)1 Job (com.google.cloud.bigquery.Job)1 JobId (com.google.cloud.bigquery.JobId)1 JobInfo (com.google.cloud.bigquery.JobInfo)1 QueryJobConfiguration (com.google.cloud.bigquery.QueryJobConfiguration)1 TableResult (com.google.cloud.bigquery.TableResult)1 ListMetricDescriptorsPagedResponse (com.google.cloud.monitoring.spi.v3.PagedResponseWrappers.ListMetricDescriptorsPagedResponse)1 ListTimeSeriesPagedResponse (com.google.cloud.monitoring.v3.MetricServiceClient.ListTimeSeriesPagedResponse)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 CreateMetricDescriptorRequest (com.google.monitoring.v3.CreateMetricDescriptorRequest)1