use of com.google.bigtable.repackaged.com.google.monitoring.v3.ListTimeSeriesRequest in project java-docs-samples by GoogleCloudPlatform.
the class Snippets method listTimeSeries.
/**
* Demonstrates listing time series using a filter.
*/
void listTimeSeries(String filter) throws IOException {
// [START monitoring_read_timeseries_simple]
MetricServiceClient metricServiceClient = MetricServiceClient.create();
String projectId = System.getProperty("projectId");
ProjectName name = ProjectName.of(projectId);
// Restrict time to last 20 minutes
long startMillis = System.currentTimeMillis() - ((60 * 20) * 1000);
TimeInterval interval = TimeInterval.newBuilder().setStartTime(Timestamps.fromMillis(startMillis)).setEndTime(Timestamps.fromMillis(System.currentTimeMillis())).build();
ListTimeSeriesRequest.Builder requestBuilder = ListTimeSeriesRequest.newBuilder().setName(name.toString()).setFilter(filter).setInterval(interval);
ListTimeSeriesRequest request = requestBuilder.build();
ListTimeSeriesPagedResponse response = metricServiceClient.listTimeSeries(request);
System.out.println("Got timeseries: ");
for (TimeSeries ts : response.iterateAll()) {
System.out.println(ts);
}
// [END monitoring_read_timeseries_simple]
}
use of com.google.bigtable.repackaged.com.google.monitoring.v3.ListTimeSeriesRequest in project java-monitoring by googleapis.
the class MetricServiceClientTest method listTimeSeriesTest3.
@Test
public void listTimeSeriesTest3() throws Exception {
TimeSeries responsesElement = TimeSeries.newBuilder().build();
ListTimeSeriesResponse expectedResponse = ListTimeSeriesResponse.newBuilder().setNextPageToken("").addAllTimeSeries(Arrays.asList(responsesElement)).build();
mockMetricService.addResponse(expectedResponse);
ProjectName name = ProjectName.of("[PROJECT]");
String filter = "filter-1274492040";
TimeInterval interval = TimeInterval.newBuilder().build();
ListTimeSeriesRequest.TimeSeriesView view = ListTimeSeriesRequest.TimeSeriesView.forNumber(0);
ListTimeSeriesPagedResponse pagedListResponse = client.listTimeSeries(name, filter, interval, view);
List<TimeSeries> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getTimeSeriesList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockMetricService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListTimeSeriesRequest actualRequest = ((ListTimeSeriesRequest) actualRequests.get(0));
Assert.assertEquals(name.toString(), actualRequest.getName());
Assert.assertEquals(filter, actualRequest.getFilter());
Assert.assertEquals(interval, actualRequest.getInterval());
Assert.assertEquals(view, actualRequest.getView());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.bigtable.repackaged.com.google.monitoring.v3.ListTimeSeriesRequest in project java-monitoring by googleapis.
the class ListTimeSeries method listTimeSeries.
public static void listTimeSeries(String filter, String projectId) throws ApiException, IOException {
// once, and can be reused for multiple requests.
try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
ProjectName projectName = ProjectName.of(projectId);
// Restrict time to last 20 minutes
long startMillis = System.currentTimeMillis() - ((60 * 20) * 1000);
TimeInterval interval = TimeInterval.newBuilder().setStartTime(Timestamps.fromMillis(startMillis)).setEndTime(Timestamps.fromMillis(System.currentTimeMillis())).build();
// Prepares the list time series request
ListTimeSeriesRequest request = ListTimeSeriesRequest.newBuilder().setName(projectName.toString()).setFilter(filter).setInterval(interval).build();
// Send the request to list the time series
MetricServiceClient.ListTimeSeriesPagedResponse response = metricServiceClient.listTimeSeries(request);
// Process the response
System.out.println("Got timeseries: ");
response.iterateAll().forEach(timeSeries -> System.out.println(timeSeries));
}
}
Aggregations