Search in sources :

Example 1 with ListTimeSeriesRequest

use of com.google.monitoring.v3.ListTimeSeriesRequest 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]
}
Also used : Aggregation(com.google.monitoring.v3.Aggregation) TimeSeries(com.google.monitoring.v3.TimeSeries) MetricServiceClient(com.google.cloud.monitoring.v3.MetricServiceClient) TimeInterval(com.google.monitoring.v3.TimeInterval) ProjectName(com.google.monitoring.v3.ProjectName) ListTimeSeriesPagedResponse(com.google.cloud.monitoring.v3.MetricServiceClient.ListTimeSeriesPagedResponse) ListTimeSeriesRequest(com.google.monitoring.v3.ListTimeSeriesRequest)

Example 2 with ListTimeSeriesRequest

use of com.google.monitoring.v3.ListTimeSeriesRequest 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());
}
Also used : TimeSeries(com.google.monitoring.v3.TimeSeries) TimeInterval(com.google.monitoring.v3.TimeInterval) ProjectName(com.google.monitoring.v3.ProjectName) ListTimeSeriesResponse(com.google.monitoring.v3.ListTimeSeriesResponse) TimeSeriesView(com.google.monitoring.v3.ListTimeSeriesRequest.TimeSeriesView) ListTimeSeriesPagedResponse(com.google.cloud.monitoring.spi.v3.PagedResponseWrappers.ListTimeSeriesPagedResponse) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) ListTimeSeriesRequest(com.google.monitoring.v3.ListTimeSeriesRequest) Test(org.junit.Test)

Example 3 with ListTimeSeriesRequest

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

the class Snippets method listTimeSeriesReduce.

/**
 * Demonstrates listing time series and aggregating and reducing them.
 */
void listTimeSeriesReduce() throws IOException {
    // [START monitoring_read_timeseries_reduce]
    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).setCrossSeriesReducer(Aggregation.Reducer.REDUCE_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_reduce]
}
Also used : Aggregation(com.google.monitoring.v3.Aggregation) TimeSeries(com.google.monitoring.v3.TimeSeries) MetricServiceClient(com.google.cloud.monitoring.v3.MetricServiceClient) TimeInterval(com.google.monitoring.v3.TimeInterval) ProjectName(com.google.monitoring.v3.ProjectName) ListTimeSeriesPagedResponse(com.google.cloud.monitoring.v3.MetricServiceClient.ListTimeSeriesPagedResponse) ListTimeSeriesRequest(com.google.monitoring.v3.ListTimeSeriesRequest)

Example 4 with ListTimeSeriesRequest

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

the class Snippets method listTimeSeriesHeaders.

// CHECKSTYLE ON: VariableDeclarationUsageDistance
/**
 * Demonstrates listing time series headers.
 */
void listTimeSeriesHeaders() throws IOException {
    // [START monitoring_read_timeseries_fields]
    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("metric.type=\"compute.googleapis.com/instance/cpu/utilization\"").setInterval(interval).setView(ListTimeSeriesRequest.TimeSeriesView.HEADERS);
    ListTimeSeriesRequest request = requestBuilder.build();
    ListTimeSeriesPagedResponse response = metricServiceClient.listTimeSeries(request);
    System.out.println("Got timeseries headers: ");
    for (TimeSeries ts : response.iterateAll()) {
        System.out.println(ts);
    }
// [END monitoring_read_timeseries_fields]
}
Also used : TimeSeries(com.google.monitoring.v3.TimeSeries) MetricServiceClient(com.google.cloud.monitoring.v3.MetricServiceClient) TimeInterval(com.google.monitoring.v3.TimeInterval) ProjectName(com.google.monitoring.v3.ProjectName) ListTimeSeriesPagedResponse(com.google.cloud.monitoring.v3.MetricServiceClient.ListTimeSeriesPagedResponse) ListTimeSeriesRequest(com.google.monitoring.v3.ListTimeSeriesRequest)

Example 5 with ListTimeSeriesRequest

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