Search in sources :

Example 1 with Snapshot

use of io.opencensus.metrics.export.Summary.Snapshot in project instrumentation-java by census-instrumentation.

the class SummaryTest method createAndGet_Snapshot.

@Test
public void createAndGet_Snapshot() {
    Snapshot snapshot = Snapshot.create(10L, 87.07, Collections.singletonList(ValueAtPercentile.create(99.5, 10.2)));
    assertThat(snapshot.getCount()).isEqualTo(10);
    assertThat(snapshot.getSum()).isWithin(TOLERANCE).of(87.07);
    assertThat(snapshot.getValueAtPercentiles()).containsExactly(ValueAtPercentile.create(99.5, 10.2));
}
Also used : Snapshot(io.opencensus.metrics.export.Summary.Snapshot) Test(org.junit.Test)

Example 2 with Snapshot

use of io.opencensus.metrics.export.Summary.Snapshot in project instrumentation-java by census-instrumentation.

the class DropWizardMetrics method collectSnapshotAndCount.

/**
 * Returns a {@code Metric} collected from {@link Snapshot}.
 *
 * @param metricName the metric name.
 * @param metricDescription the metric description.
 * @param labelKeys metric label keys
 * @param labelValues metric label values
 * @param codahaleSnapshot the snapshot object to collect
 * @param count the value or count
 * @return a {@code Metric}.
 */
private Metric collectSnapshotAndCount(String metricName, String metricDescription, List<LabelKey> labelKeys, List<LabelValue> labelValues, String unit, io.dropwizard.metrics5.Snapshot codahaleSnapshot, long count) {
    List<ValueAtPercentile> valueAtPercentiles = Arrays.asList(ValueAtPercentile.create(50.0, codahaleSnapshot.getMedian()), ValueAtPercentile.create(75.0, codahaleSnapshot.get75thPercentile()), ValueAtPercentile.create(98.0, codahaleSnapshot.get98thPercentile()), ValueAtPercentile.create(99.0, codahaleSnapshot.get99thPercentile()), ValueAtPercentile.create(99.9, codahaleSnapshot.get999thPercentile()));
    Snapshot snapshot = Snapshot.create((long) codahaleSnapshot.size(), 0.0, valueAtPercentiles);
    Point point = Point.create(Value.summaryValue(Summary.create(count, 0.0, snapshot)), clock.now());
    // TODO(mayurkale): OPTIMIZATION: Cache the MetricDescriptor objects.
    MetricDescriptor metricDescriptor = MetricDescriptor.create(metricName, metricDescription, unit, Type.SUMMARY, labelKeys);
    TimeSeries timeSeries = TimeSeries.createWithOnePoint(labelValues, point, cumulativeStartTimestamp);
    return Metric.createWithOneTimeSeries(metricDescriptor, timeSeries);
}
Also used : ValueAtPercentile(io.opencensus.metrics.export.Summary.Snapshot.ValueAtPercentile) Snapshot(io.opencensus.metrics.export.Summary.Snapshot) MetricDescriptor(io.opencensus.metrics.export.MetricDescriptor) TimeSeries(io.opencensus.metrics.export.TimeSeries) Point(io.opencensus.metrics.export.Point)

Example 3 with Snapshot

use of io.opencensus.metrics.export.Summary.Snapshot in project instrumentation-java by census-instrumentation.

the class DropWizardMetrics method collectSnapshotAndCount.

/**
 * Returns a {@code Metric} collected from {@link Snapshot}.
 *
 * @param metricName the metric name.
 * @param metricDescription the metric description.
 * @param unit the metric descriptor unit.
 * @param codahaleSnapshot the snapshot object to collect
 * @param count the value or count
 * @return a {@code Metric}.
 */
private Metric collectSnapshotAndCount(String metricName, String metricDescription, String unit, com.codahale.metrics.Snapshot codahaleSnapshot, long count) {
    List<ValueAtPercentile> valueAtPercentiles = Arrays.asList(ValueAtPercentile.create(50.0, codahaleSnapshot.getMedian()), ValueAtPercentile.create(75.0, codahaleSnapshot.get75thPercentile()), ValueAtPercentile.create(98.0, codahaleSnapshot.get98thPercentile()), ValueAtPercentile.create(99.0, codahaleSnapshot.get99thPercentile()), ValueAtPercentile.create(99.9, codahaleSnapshot.get999thPercentile()));
    Snapshot snapshot = Snapshot.create((long) codahaleSnapshot.size(), 0.0, valueAtPercentiles);
    Point point = Point.create(Value.summaryValue(Summary.create(count, 0.0, snapshot)), clock.now());
    // TODO(mayurkale): OPTIMIZATION: Cache the MetricDescriptor objects.
    MetricDescriptor metricDescriptor = MetricDescriptor.create(metricName, metricDescription, unit, Type.SUMMARY, Collections.<LabelKey>emptyList());
    TimeSeries timeSeries = TimeSeries.createWithOnePoint(Collections.<LabelValue>emptyList(), point, cumulativeStartTimestamp);
    return Metric.createWithOneTimeSeries(metricDescriptor, timeSeries);
}
Also used : ValueAtPercentile(io.opencensus.metrics.export.Summary.Snapshot.ValueAtPercentile) Snapshot(io.opencensus.metrics.export.Summary.Snapshot) MetricDescriptor(io.opencensus.metrics.export.MetricDescriptor) TimeSeries(io.opencensus.metrics.export.TimeSeries) Point(io.opencensus.metrics.export.Point)

Example 4 with Snapshot

use of io.opencensus.metrics.export.Summary.Snapshot in project instrumentation-java by census-instrumentation.

the class SummaryTest method createAndGet_Summary.

@Test
public void createAndGet_Summary() {
    Snapshot snapshot = Snapshot.create(10L, 87.07, Collections.singletonList(ValueAtPercentile.create(99.5, 10.2)));
    Summary summary = Summary.create(10L, 6.6, snapshot);
    assertThat(summary.getCount()).isEqualTo(10);
    assertThat(summary.getSum()).isWithin(TOLERANCE).of(6.6);
    assertThat(summary.getSnapshot()).isEqualTo(snapshot);
}
Also used : Snapshot(io.opencensus.metrics.export.Summary.Snapshot) Test(org.junit.Test)

Example 5 with Snapshot

use of io.opencensus.metrics.export.Summary.Snapshot in project instrumentation-java by census-instrumentation.

the class SummaryTest method createAndGet_Snapshot_WithNullCountAndSum.

@Test
public void createAndGet_Snapshot_WithNullCountAndSum() {
    Snapshot snapshot = Snapshot.create(null, null, Collections.singletonList(ValueAtPercentile.create(99.5, 10.2)));
    assertThat(snapshot.getCount()).isNull();
    assertThat(snapshot.getSum()).isNull();
    assertThat(snapshot.getValueAtPercentiles()).containsExactly(ValueAtPercentile.create(99.5, 10.2));
}
Also used : Snapshot(io.opencensus.metrics.export.Summary.Snapshot) Test(org.junit.Test)

Aggregations

Snapshot (io.opencensus.metrics.export.Summary.Snapshot)5 Test (org.junit.Test)3 MetricDescriptor (io.opencensus.metrics.export.MetricDescriptor)2 Point (io.opencensus.metrics.export.Point)2 ValueAtPercentile (io.opencensus.metrics.export.Summary.Snapshot.ValueAtPercentile)2 TimeSeries (io.opencensus.metrics.export.TimeSeries)2