Java Code Examples for com.google.api.services.monitoring.v3.model.TimeSeries#getPoints()

The following examples show how to use com.google.api.services.monitoring.v3.model.TimeSeries#getPoints() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StackdriverWriterTest.java    From java-monitoring-client-library with Apache License 2.0 6 votes vote down vote up
@Test
public void getEncodedTimeSeries_cumulativeMetricPoint_ZeroInterval_encodesGreaterEndTime()
    throws Exception {
  StackdriverWriter writer =
      new StackdriverWriter(client, PROJECT, MONITORED_RESOURCE, MAX_QPS, MAX_POINTS_PER_REQUEST);
  MetricPoint<Long> nativePoint =
      MetricPoint.create(
          metric,
          ImmutableList.of("foo"),
          Instant.ofEpochMilli(1337),
          Instant.ofEpochMilli(1337),
          10L);

  TimeSeries timeSeries = writer.getEncodedTimeSeries(nativePoint);

  assertThat(timeSeries.getValueType()).isEqualTo("INT64");
  assertThat(timeSeries.getMetricKind()).isEqualTo("CUMULATIVE");
  List<Point> points = timeSeries.getPoints();
  assertThat(points).hasSize(1);
  Point point = points.get(0);
  assertThat(point.getValue().getInt64Value()).isEqualTo(10L);
  assertThat(point.getInterval().getStartTime()).isEqualTo("1970-01-01T00:00:01.337Z");
  assertThat(point.getInterval().getEndTime()).isEqualTo("1970-01-01T00:00:01.338Z");
}
 
Example 2
Source File: StackdriverWriterTest.java    From java-monitoring-client-library with Apache License 2.0 6 votes vote down vote up
@Test
public void getEncodedTimeSeries_cumulativeMetricPoint_nonZeroInterval_encodesSameInterval()
    throws Exception {
  StackdriverWriter writer =
      new StackdriverWriter(client, PROJECT, MONITORED_RESOURCE, MAX_QPS, MAX_POINTS_PER_REQUEST);
  MetricPoint<Long> nativePoint =
      MetricPoint.create(
          metric,
          ImmutableList.of("foo"),
          Instant.ofEpochMilli(1337),
          Instant.ofEpochMilli(1339),
          10L);

  TimeSeries timeSeries = writer.getEncodedTimeSeries(nativePoint);

  assertThat(timeSeries.getValueType()).isEqualTo("INT64");
  assertThat(timeSeries.getMetricKind()).isEqualTo("CUMULATIVE");
  List<Point> points = timeSeries.getPoints();
  assertThat(points).hasSize(1);
  Point point = points.get(0);
  assertThat(point.getValue().getInt64Value()).isEqualTo(10L);
  assertThat(point.getInterval().getStartTime()).isEqualTo("1970-01-01T00:00:01.337Z");
  assertThat(point.getInterval().getEndTime()).isEqualTo("1970-01-01T00:00:01.339Z");
}
 
Example 3
Source File: StackdriverWriterTest.java    From java-monitoring-client-library with Apache License 2.0 6 votes vote down vote up
@Test
public void getEncodedTimeSeries_booleanMetric_encodes() throws Exception {
  StackdriverWriter writer =
      new StackdriverWriter(client, PROJECT, MONITORED_RESOURCE, MAX_QPS, MAX_POINTS_PER_REQUEST);

  MetricDescriptor boolDescriptor = StackdriverWriter.encodeMetricDescriptor(boolMetric);
  when(metricDescriptorCreate.execute()).thenReturn(boolDescriptor);
  MetricPoint<Boolean> nativePoint =
      MetricPoint.create(boolMetric, ImmutableList.of("foo"), Instant.ofEpochMilli(1337), true);

  TimeSeries timeSeries = writer.getEncodedTimeSeries(nativePoint);

  assertThat(timeSeries.getValueType()).isEqualTo("BOOL");
  assertThat(timeSeries.getMetricKind()).isEqualTo("GAUGE");
  List<Point> points = timeSeries.getPoints();
  assertThat(points).hasSize(1);
  Point point = points.get(0);
  assertThat(point.getValue().getBoolValue()).isEqualTo(true);
  assertThat(point.getInterval().getEndTime()).isEqualTo("1970-01-01T00:00:01.337Z");
  assertThat(point.getInterval().getStartTime()).isEqualTo("1970-01-01T00:00:01.337Z");
}
 
Example 4
Source File: StackdriverWriterTest.java    From java-monitoring-client-library with Apache License 2.0 5 votes vote down vote up
@Test
public void getEncodedTimeSeries_distributionMetricCustomFitter_encodes() throws Exception {
  StackdriverWriter writer =
      new StackdriverWriter(client, PROJECT, MONITORED_RESOURCE, MAX_QPS, MAX_POINTS_PER_REQUEST);

  MetricDescriptor descriptor = StackdriverWriter.encodeMetricDescriptor(distributionMetric);
  when(metricDescriptorCreate.execute()).thenReturn(descriptor);
  MutableDistribution distribution =
      new MutableDistribution(CustomFitter.create(ImmutableSet.of(5.0)));
  distribution.add(10.0, 5L);
  distribution.add(0.0, 5L);
  MetricPoint<Distribution> nativePoint =
      MetricPoint.create(
          distributionMetric, ImmutableList.of("foo"), Instant.ofEpochMilli(1337), distribution);

  TimeSeries timeSeries = writer.getEncodedTimeSeries(nativePoint);

  assertThat(timeSeries.getValueType()).isEqualTo("DISTRIBUTION");
  assertThat(timeSeries.getMetricKind()).isEqualTo("GAUGE");
  List<Point> points = timeSeries.getPoints();
  assertThat(points).hasSize(1);
  Point point = points.get(0);
  assertThat(point.getValue().getDistributionValue())
      .isEqualTo(
          new com.google.api.services.monitoring.v3.model.Distribution()
              .setMean(5.0)
              .setSumOfSquaredDeviation(250.0)
              .setCount(10L)
              .setBucketCounts(ImmutableList.of(5L, 5L))
              .setBucketOptions(
                  new BucketOptions()
                      .setExplicitBuckets(new Explicit().setBounds(ImmutableList.of(5.0)))));
  assertThat(point.getInterval().getEndTime()).isEqualTo("1970-01-01T00:00:01.337Z");
  assertThat(point.getInterval().getStartTime()).isEqualTo("1970-01-01T00:00:01.337Z");
}
 
Example 5
Source File: StackdriverWriterTest.java    From java-monitoring-client-library with Apache License 2.0 5 votes vote down vote up
@Test
public void getEncodedTimeSeries_distributionMetricLinearFitter_encodes() throws Exception {
  StackdriverWriter writer =
      new StackdriverWriter(client, PROJECT, MONITORED_RESOURCE, MAX_QPS, MAX_POINTS_PER_REQUEST);

  MetricDescriptor descriptor = StackdriverWriter.encodeMetricDescriptor(distributionMetric);
  when(metricDescriptorCreate.execute()).thenReturn(descriptor);
  MutableDistribution distribution = new MutableDistribution(LinearFitter.create(2, 5.0, 3.0));
  distribution.add(0.0, 1L);
  distribution.add(3.0, 2L);
  distribution.add(10.0, 5L);
  distribution.add(20.0, 5L);
  MetricPoint<Distribution> nativePoint =
      MetricPoint.create(
          distributionMetric, ImmutableList.of("foo"), Instant.ofEpochMilli(1337), distribution);

  TimeSeries timeSeries = writer.getEncodedTimeSeries(nativePoint);

  assertThat(timeSeries.getValueType()).isEqualTo("DISTRIBUTION");
  assertThat(timeSeries.getMetricKind()).isEqualTo("GAUGE");
  List<Point> points = timeSeries.getPoints();
  assertThat(points).hasSize(1);
  Point point = points.get(0);
  assertThat(point.getValue().getDistributionValue())
      .isEqualTo(
          new com.google.api.services.monitoring.v3.model.Distribution()
              .setMean(12.0)
              .setSumOfSquaredDeviation(646.0)
              .setCount(13L)
              .setBucketCounts(ImmutableList.of(1L, 2L, 5L, 5L))
              .setBucketOptions(
                  new BucketOptions()
                      .setLinearBuckets(
                          new Linear().setNumFiniteBuckets(2).setWidth(5.0).setOffset(3.0))));
  assertThat(point.getInterval().getEndTime()).isEqualTo("1970-01-01T00:00:01.337Z");
  assertThat(point.getInterval().getStartTime()).isEqualTo("1970-01-01T00:00:01.337Z");
}
 
Example 6
Source File: StackdriverWriterTest.java    From java-monitoring-client-library with Apache License 2.0 4 votes vote down vote up
@Test
public void getEncodedTimeSeries_gaugeMetricPoint_zeroInterval_encodesSameInterval()
    throws Exception {
  when(metric.getMetricSchema())
      .thenReturn(
          MetricSchema.create(
              "/name",
              "desc",
              "vdn",
              Kind.GAUGE,
              ImmutableSet.of(LabelDescriptor.create("label1", "desc1"))));
  // Store in an intermediate value, because Mockito hates when mocks are evaluated inside of
  // thenReturn() methods.
  MetricPoint<Long> testPoint =
      MetricPoint.create(metric, ImmutableList.of("foo"), Instant.ofEpochMilli(1337), 10L);
  when(metric.getTimestampedValues()).thenReturn(ImmutableList.of(testPoint));
  // Store in an intermediate value, because Mockito hates when mocks are evaluated inside of
  // thenReturn() methods.
  MetricDescriptor descriptor = StackdriverWriter.encodeMetricDescriptor(metric);
  when(metricDescriptorCreate.execute()).thenReturn(descriptor);
  StackdriverWriter writer =
      new StackdriverWriter(client, PROJECT, MONITORED_RESOURCE, MAX_QPS, MAX_POINTS_PER_REQUEST);
  MetricPoint<Long> nativePoint =
      MetricPoint.create(
          metric,
          ImmutableList.of("foo"),
          Instant.ofEpochMilli(1337),
          Instant.ofEpochMilli(1337),
          10L);

  TimeSeries timeSeries = writer.getEncodedTimeSeries(nativePoint);

  assertThat(timeSeries.getValueType()).isEqualTo("INT64");
  assertThat(timeSeries.getMetricKind()).isEqualTo("GAUGE");
  List<Point> points = timeSeries.getPoints();
  assertThat(points).hasSize(1);
  Point point = points.get(0);
  assertThat(point.getValue().getInt64Value()).isEqualTo(10L);
  assertThat(point.getInterval().getStartTime()).isEqualTo("1970-01-01T00:00:01.337Z");
  assertThat(point.getInterval().getEndTime()).isEqualTo("1970-01-01T00:00:01.337Z");
}
 
Example 7
Source File: StackdriverWriterTest.java    From java-monitoring-client-library with Apache License 2.0 4 votes vote down vote up
@Test
public void getEncodedTimeSeries_distributionMetricExponentialFitter_encodes() throws Exception {
  StackdriverWriter writer =
      new StackdriverWriter(client, PROJECT, MONITORED_RESOURCE, MAX_QPS, MAX_POINTS_PER_REQUEST);

  MetricDescriptor descriptor = StackdriverWriter.encodeMetricDescriptor(distributionMetric);
  when(metricDescriptorCreate.execute()).thenReturn(descriptor);
  MutableDistribution distribution =
      new MutableDistribution(ExponentialFitter.create(2, 3.0, 0.5));
  distribution.add(0.0, 1L);
  distribution.add(3.0, 2L);
  distribution.add(10.0, 5L);
  distribution.add(20.0, 5L);
  MetricPoint<Distribution> nativePoint =
      MetricPoint.create(
          distributionMetric, ImmutableList.of("foo"), Instant.ofEpochMilli(1337), distribution);

  TimeSeries timeSeries = writer.getEncodedTimeSeries(nativePoint);

  assertThat(timeSeries.getValueType()).isEqualTo("DISTRIBUTION");
  assertThat(timeSeries.getMetricKind()).isEqualTo("GAUGE");
  List<Point> points = timeSeries.getPoints();
  assertThat(points).hasSize(1);
  Point point = points.get(0);
  assertThat(point.getValue().getDistributionValue())
      .isEqualTo(
          new com.google.api.services.monitoring.v3.model.Distribution()
              .setMean(12.0)
              .setSumOfSquaredDeviation(646.0)
              .setCount(13L)
              .setBucketCounts(ImmutableList.of(1L, 0L, 2L, 10L))
              .setBucketOptions(
                  new BucketOptions()
                      .setExponentialBuckets(
                          new Exponential()
                              .setNumFiniteBuckets(2)
                              .setGrowthFactor(3.0)
                              .setScale(0.5))));
  assertThat(point.getInterval().getEndTime()).isEqualTo("1970-01-01T00:00:01.337Z");
  assertThat(point.getInterval().getStartTime()).isEqualTo("1970-01-01T00:00:01.337Z");
}