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]
}
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);
}
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;
}
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;
}
}
}
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);
}
Aggregations