use of com.google.api.ads.admanager.axis.v202205.TimeSeries in project java-docs-samples by GoogleCloudPlatform.
the class Snippets method listTimeSeriesAggregrate.
/**
* Demonstrates listing time series and aggregating them.
*/
void listTimeSeriesAggregrate() throws IOException {
// [START monitoring_read_timeseries_align]
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();
Aggregation aggregation = Aggregation.newBuilder().setAlignmentPeriod(Duration.newBuilder().setSeconds(600).build()).setPerSeriesAligner(Aggregation.Aligner.ALIGN_MEAN).build();
ListTimeSeriesRequest.Builder requestBuilder = ListTimeSeriesRequest.newBuilder().setName(name.toString()).setFilter("metric.type=\"compute.googleapis.com/instance/cpu/utilization\"").setInterval(interval).setAggregation(aggregation);
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_align]
}
use of com.google.api.ads.admanager.axis.v202205.TimeSeries in project spring-cloud-gcp by GoogleCloudPlatform.
the class HealthTrackerImpl method getBackLogMessages.
private Optional<Long> getBackLogMessages(long currentMillis) {
TimeInterval timeInterval = timeInterval(currentMillis);
ListTimeSeriesResponse timeSeriesResponse = metricServiceClient.listTimeSeries(ProjectName.of(projectSubscriptionName.getProject()), undeliveredFilter, timeInterval, FULL).getPage().getResponse();
if (timeSeriesResponse.getTimeSeriesCount() > 0) {
TimeSeries timeSeries = timeSeriesResponse.getTimeSeries(0);
if (timeSeries.getPointsCount() > 0) {
return Optional.of(timeSeries.getPoints(0).getValue().getInt64Value());
}
}
return Optional.empty();
}
use of com.google.api.ads.admanager.axis.v202205.TimeSeries in project spring-cloud-gcp by GoogleCloudPlatform.
the class HealthTrackerImplTests method noMessagesOverThresholdNoProcessing.
@Test
void noMessagesOverThresholdNoProcessing() throws InterruptedException {
LockSupport.parkNanos(1001 * 1000000);
ListTimeSeriesPagedResponse listTimeSeriesPagedResponse = mock(ListTimeSeriesPagedResponse.class);
TimeSeries timeSeries = TimeSeries.newBuilder().addPoints(Point.newBuilder().setValue(TypedValue.newBuilder().setInt64Value(100).build()).build()).build();
ListTimeSeriesResponse timeSeriesResponse = ListTimeSeriesResponse.newBuilder().addTimeSeries(timeSeries).build();
ListTimeSeriesPage listTimeSeriesPage = mock(ListTimeSeriesPage.class);
when(listTimeSeriesPagedResponse.getPage()).thenReturn(listTimeSeriesPage);
when(listTimeSeriesPage.getResponse()).thenReturn(timeSeriesResponse);
doReturn(listTimeSeriesPagedResponse).when(metricServiceClient).listTimeSeries(any(ProjectName.class), anyString(), any(), any());
long messagesOverThreshold = healthTracker.messagesOverThreshold();
assertThat(messagesOverThreshold).isNegative();
}
use of com.google.api.ads.admanager.axis.v202205.TimeSeries in project google-cloud-java by GoogleCloudPlatform.
the class MetricServiceClientTest method listTimeSeriesTest.
@Test
@SuppressWarnings("all")
public void listTimeSeriesTest() {
String nextPageToken = "";
TimeSeries timeSeriesElement = TimeSeries.newBuilder().build();
List<TimeSeries> timeSeries = Arrays.asList(timeSeriesElement);
ListTimeSeriesResponse expectedResponse = ListTimeSeriesResponse.newBuilder().setNextPageToken(nextPageToken).addAllTimeSeries(timeSeries).build();
mockMetricService.addResponse(expectedResponse);
ProjectName name = ProjectName.create("[PROJECT]");
String filter = "filter-1274492040";
TimeInterval interval = TimeInterval.newBuilder().build();
ListTimeSeriesRequest.TimeSeriesView view = ListTimeSeriesRequest.TimeSeriesView.FULL;
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<GeneratedMessageV3> actualRequests = mockMetricService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListTimeSeriesRequest actualRequest = (ListTimeSeriesRequest) actualRequests.get(0);
Assert.assertEquals(name, actualRequest.getNameAsProjectName());
Assert.assertEquals(filter, actualRequest.getFilter());
Assert.assertEquals(interval, actualRequest.getInterval());
Assert.assertEquals(view, actualRequest.getView());
}
use of com.google.api.ads.admanager.axis.v202205.TimeSeries in project google-cloud-java by GoogleCloudPlatform.
the class MetricServiceClientTest method createTimeSeriesExceptionTest.
@Test
@SuppressWarnings("all")
public void createTimeSeriesExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockMetricService.addException(exception);
try {
ProjectName name = ProjectName.create("[PROJECT]");
List<TimeSeries> timeSeries = new ArrayList<>();
client.createTimeSeries(name, timeSeries);
Assert.fail("No exception raised");
} catch (ApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
}
}
Aggregations