Search in sources :

Example 36 with TimeSeries

use of com.google.bigtable.repackaged.com.google.monitoring.v3.TimeSeries 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)

Example 37 with TimeSeries

use of com.google.bigtable.repackaged.com.google.monitoring.v3.TimeSeries in project workbench by all-of-us.

the class WorkspaceAdminServiceTest method getCloudStorageTraffic_sortsPointsByTimestamp.

@Test
public void getCloudStorageTraffic_sortsPointsByTimestamp() {
    TimeSeries timeSeries = TimeSeries.newBuilder().addPoints(Point.newBuilder().setInterval(TimeInterval.newBuilder().setEndTime(Timestamps.fromMillis(2000))).setValue(TypedValue.newBuilder().setDoubleValue(1234))).addPoints(Point.newBuilder().setInterval(TimeInterval.newBuilder().setEndTime(Timestamps.fromMillis(1000))).setValue(TypedValue.newBuilder().setDoubleValue(1234))).build();
    when(mockCloudMonitoringService.getCloudStorageReceivedBytes(anyString(), any(Duration.class))).thenReturn(Collections.singletonList(timeSeries));
    final CloudStorageTraffic cloudStorageTraffic = workspaceAdminService.getCloudStorageTraffic(WORKSPACE_NAMESPACE);
    assertThat(cloudStorageTraffic.getReceivedBytes().stream().map(TimeSeriesPoint::getTimestamp).collect(Collectors.toList())).containsExactly(1000L, 2000L);
}
Also used : TimeSeries(com.google.monitoring.v3.TimeSeries) Duration(java.time.Duration) CloudStorageTraffic(org.pmiops.workbench.model.CloudStorageTraffic) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.jupiter.api.Test)

Example 38 with TimeSeries

use of com.google.bigtable.repackaged.com.google.monitoring.v3.TimeSeries in project workbench by all-of-us.

the class WorkspaceAdminServiceImpl method getCloudStorageTraffic.

@Override
public CloudStorageTraffic getCloudStorageTraffic(String workspaceNamespace) {
    CloudStorageTraffic response = new CloudStorageTraffic().receivedBytes(new ArrayList<>());
    String googleProject = getWorkspaceByNamespaceOrThrow(workspaceNamespace).getGoogleProject();
    for (TimeSeries timeSeries : cloudMonitoringService.getCloudStorageReceivedBytes(googleProject, TRAILING_TIME_TO_QUERY)) {
        for (Point point : timeSeries.getPointsList()) {
            response.addReceivedBytesItem(new TimeSeriesPoint().timestamp(Timestamps.toMillis(point.getInterval().getEndTime())).value(point.getValue().getDoubleValue()));
        }
    }
    response.getReceivedBytes().sort(Comparator.comparing(TimeSeriesPoint::getTimestamp));
    return response;
}
Also used : TimeSeries(com.google.monitoring.v3.TimeSeries) TimeSeriesPoint(org.pmiops.workbench.model.TimeSeriesPoint) CloudStorageTraffic(org.pmiops.workbench.model.CloudStorageTraffic) Point(com.google.monitoring.v3.Point) TimeSeriesPoint(org.pmiops.workbench.model.TimeSeriesPoint)

Example 39 with TimeSeries

use of com.google.bigtable.repackaged.com.google.monitoring.v3.TimeSeries in project spf4j by zolyfarkas.

the class TimeSeriesDatabase method tail.

@SuppressFBWarnings("MDM_THREAD_YIELD")
public void tail(final long pollMillis, final long from, final TSDataHandler handler) throws IOException {
    Map<String, TSTable> lastState = new HashMap<>();
    long lastSize = 0;
    while (!Thread.currentThread().isInterrupted() && !handler.finish()) {
        long currSize = this.file.length();
        if (currSize > lastSize) {
            // see if we have new Tables;
            reReadTableInfos();
            Map<String, TSTable> currState = getTsTables();
            for (String tableName : Sets.difference(currState.keySet(), lastState.keySet())) {
                handler.newTable(tableName, currState.get(tableName).getColumnNames());
            }
            for (TSTable table : currState.values()) {
                final String tableName = table.getTableName();
                TSTable prevTableState = lastState.get(tableName);
                final long currLastDataFragment = table.getLastDataFragment();
                if (prevTableState == null) {
                    long lastDataFragment = table.getFirstDataFragment();
                    if (lastDataFragment > 0) {
                        TimeSeries data = read(from, Long.MAX_VALUE, lastDataFragment, currLastDataFragment, false);
                        handler.newData(tableName, data);
                    }
                } else {
                    long lastDataFragment = prevTableState.getLastDataFragment();
                    if (lastDataFragment == 0) {
                        lastDataFragment = table.getFirstDataFragment();
                        if (lastDataFragment > 0) {
                            TimeSeries data = read(from, Long.MAX_VALUE, lastDataFragment, currLastDataFragment, false);
                            handler.newData(tableName, data);
                        }
                    } else if (currLastDataFragment > lastDataFragment) {
                        TimeSeries data = read(from, Long.MAX_VALUE, lastDataFragment, currLastDataFragment, true);
                        handler.newData(tableName, data);
                    }
                }
            }
            lastState = currState;
        }
        lastSize = currSize;
        try {
            Thread.sleep(pollMillis);
        } catch (InterruptedException ex) {
            Thread.currentThread().interrupt();
            break;
        }
    }
}
Also used : TimeSeries(org.spf4j.tsdb2.TimeSeries) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 40 with TimeSeries

use of com.google.bigtable.repackaged.com.google.monitoring.v3.TimeSeries in project spf4j by zolyfarkas.

the class TimeSeriesDatabase method createHeatJFreeChart.

public JFreeChart createHeatJFreeChart(final String tableName, final long startTime, final long endTime) throws IOException {
    TSTable info = this.getTSTable(tableName);
    TimeSeries data = this.read(tableName, startTime, endTime);
    return createHeatJFreeChart(data, info);
}
Also used : TimeSeries(org.spf4j.tsdb2.TimeSeries)

Aggregations

TimeSeries (com.google.monitoring.v3.TimeSeries)36 Test (org.junit.Test)23 ArrayList (java.util.ArrayList)18 ProjectName (com.google.monitoring.v3.ProjectName)17 TimeInterval (com.google.monitoring.v3.TimeInterval)14 ListTimeSeriesPagedResponse (com.google.cloud.monitoring.v3.MetricServiceClient.ListTimeSeriesPagedResponse)11 CreateTimeSeriesRequest (com.google.monitoring.v3.CreateTimeSeriesRequest)11 TimeSeries (org.spf4j.tsdb2.TimeSeries)11 ListTimeSeriesRequest (com.google.monitoring.v3.ListTimeSeriesRequest)10 MetricServiceClient (com.google.cloud.monitoring.v3.MetricServiceClient)8 ListTimeSeriesResponse (com.google.monitoring.v3.ListTimeSeriesResponse)8 AbstractMessage (com.google.protobuf.AbstractMessage)8 Point (com.google.monitoring.v3.Point)6 MonitoredResource (com.google.api.MonitoredResource)5 Empty (com.google.protobuf.Empty)5 StatusRuntimeException (io.grpc.StatusRuntimeException)5 HashMap (java.util.HashMap)5 Metric (com.google.api.Metric)4 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)4 TypedValue (com.google.monitoring.v3.TypedValue)3