Search in sources :

Example 6 with ListTimeSeriesRequest

use of com.google.monitoring.v3.ListTimeSeriesRequest in project java-docs-samples by GoogleCloudPlatform.

the class BigQueryRunner method getTimeSeriesValues.

// [START bigquery_logging_list_time_series]
public List<TimeSeriesSummary> getTimeSeriesValues() {
    List<TimeSeriesSummary> summaries = Lists.newArrayList();
    createMetricsIfNeeded();
    for (MetricDescriptor metric : REQUIRED_METRICS) {
        ListTimeSeriesRequest listTimeSeriesRequest = ListTimeSeriesRequest.newBuilder().setName(projectName).setFilter(String.format("metric.type = \"%s\"", metric.getType())).setInterval(TimeInterval.newBuilder().setStartTime(Timestamps.subtract(Timestamps.fromMillis(System.currentTimeMillis()), com.google.protobuf.Duration.newBuilder().setSeconds(// 30 days ago
        60L * 60L * 24L * 30L).build())).setEndTime(Timestamps.fromMillis(System.currentTimeMillis())).build()).build();
        try {
            ListTimeSeriesPagedResponse listTimeSeriesResponse = client.listTimeSeries(listTimeSeriesRequest);
            ArrayList<TimeSeries> timeSeries = Lists.newArrayList(listTimeSeriesResponse.iterateAll());
            summaries.addAll(timeSeries.stream().map(TimeSeriesSummary::fromTimeSeries).collect(Collectors.toList()));
        } catch (RuntimeException ex) {
            os.println("MetricDescriptors not yet synced. Please try again in a moment.");
        }
    }
    return summaries;
}
Also used : MetricDescriptor(com.google.api.MetricDescriptor) TimeSeries(com.google.monitoring.v3.TimeSeries) ListTimeSeriesPagedResponse(com.google.cloud.monitoring.v3.MetricServiceClient.ListTimeSeriesPagedResponse) ListTimeSeriesRequest(com.google.monitoring.v3.ListTimeSeriesRequest)

Aggregations

ListTimeSeriesRequest (com.google.monitoring.v3.ListTimeSeriesRequest)6 TimeSeries (com.google.monitoring.v3.TimeSeries)6 ListTimeSeriesPagedResponse (com.google.cloud.monitoring.v3.MetricServiceClient.ListTimeSeriesPagedResponse)5 ProjectName (com.google.monitoring.v3.ProjectName)5 TimeInterval (com.google.monitoring.v3.TimeInterval)5 MetricServiceClient (com.google.cloud.monitoring.v3.MetricServiceClient)4 Aggregation (com.google.monitoring.v3.Aggregation)2 MetricDescriptor (com.google.api.MetricDescriptor)1 ListTimeSeriesPagedResponse (com.google.cloud.monitoring.spi.v3.PagedResponseWrappers.ListTimeSeriesPagedResponse)1 TimeSeriesView (com.google.monitoring.v3.ListTimeSeriesRequest.TimeSeriesView)1 ListTimeSeriesResponse (com.google.monitoring.v3.ListTimeSeriesResponse)1 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)1 Test (org.junit.Test)1