Search in sources :

Example 26 with Metric

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

the class DerivedLongGaugeImplTest method createTimeSeries_WithObjFunction.

@Test
public void createTimeSeries_WithObjFunction() {
    derivedLongGauge.createTimeSeries(LABEL_VALUES, new QueueManager(), queueManagerFunction);
    Metric metric = derivedLongGauge.getMetric(testClock);
    assertThat(metric).isNotNull();
    assertThat(metric).isEqualTo(Metric.createWithOneTimeSeries(METRIC_DESCRIPTOR, TimeSeries.createWithOnePoint(LABEL_VALUES, Point.create(Value.longValue(2), TEST_TIME), null)));
}
Also used : Metric(io.opencensus.metrics.export.Metric) Test(org.junit.Test)

Example 27 with Metric

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

the class DoubleGaugeImplTest method getOrCreateTimeSeries_WithNegativePointValues.

@Test
public void getOrCreateTimeSeries_WithNegativePointValues() {
    DoublePoint point = doubleGauge.getOrCreateTimeSeries(LABEL_VALUES);
    point.add(-100);
    point.add(-33);
    Metric metric = doubleGauge.getMetric(testClock);
    assertThat(metric).isNotNull();
    assertThat(metric.getMetricDescriptor()).isEqualTo(METRIC_DESCRIPTOR);
    assertThat(metric.getTimeSeriesList().size()).isEqualTo(1);
    assertThat(metric.getTimeSeriesList().get(0).getPoints().size()).isEqualTo(1);
    assertThat(metric.getTimeSeriesList().get(0).getPoints().get(0).getValue()).isEqualTo(Value.doubleValue(-133));
    assertThat(metric.getTimeSeriesList().get(0).getPoints().get(0).getTimestamp()).isEqualTo(TEST_TIME);
    assertThat(metric.getTimeSeriesList().get(0).getStartTimestamp()).isNull();
}
Also used : DoublePoint(io.opencensus.metrics.DoubleGauge.DoublePoint) Metric(io.opencensus.metrics.export.Metric) Test(org.junit.Test)

Example 28 with Metric

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

the class MeasureToViewMap method getMetrics.

synchronized List<Metric> getMetrics(Clock clock, State state) {
    List<Metric> metrics = new ArrayList<Metric>();
    Timestamp now = clock.now();
    for (Entry<String, MutableViewData> entry : mutableMap.entries()) {
        Metric metric = entry.getValue().toMetric(now, state);
        if (metric != null) {
            metrics.add(metric);
        }
    }
    return metrics;
}
Also used : ArrayList(java.util.ArrayList) Metric(io.opencensus.metrics.export.Metric) Timestamp(io.opencensus.common.Timestamp)

Example 29 with Metric

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

the class DropWizardMetricsTest method collect_Timer.

@Test
public void collect_Timer() throws InterruptedException {
    Timer timer = metricRegistry.timer("requests");
    Timer.Context context = timer.time();
    Thread.sleep(1L);
    context.stop();
    ArrayList<Metric> metrics = new ArrayList<>(dropWizardMetrics.getMetrics());
    assertThat(metrics.size()).isEqualTo(1);
    assertThat(metrics.get(0).getMetricDescriptor()).isEqualTo(MetricDescriptor.create("codahale_requests_timer", "Collected from codahale (metric=requests, " + "type=com.codahale.metrics.Timer)", NS_UNIT, Type.SUMMARY, Collections.<LabelKey>emptyList()));
    assertThat(metrics.get(0).getTimeSeriesList().size()).isEqualTo(1);
    assertThat(metrics.get(0).getTimeSeriesList().get(0).getLabelValues().size()).isEqualTo(0);
    assertThat(metrics.get(0).getTimeSeriesList().get(0).getPoints().size()).isEqualTo(1);
    assertThat(metrics.get(0).getTimeSeriesList().get(0).getPoints().get(0).getValue()).isEqualTo(Value.summaryValue(Summary.create(1L, 0.0, Snapshot.create(1L, 0.0, Arrays.asList(ValueAtPercentile.create(50.0, timer.getSnapshot().getMedian()), ValueAtPercentile.create(75.0, timer.getSnapshot().get75thPercentile()), ValueAtPercentile.create(98.0, timer.getSnapshot().get98thPercentile()), ValueAtPercentile.create(99.0, timer.getSnapshot().get99thPercentile()), ValueAtPercentile.create(99.9, timer.getSnapshot().get999thPercentile()))))));
    assertThat(metrics.get(0).getTimeSeriesList().get(0).getStartTimestamp()).isNotNull();
}
Also used : Timer(com.codahale.metrics.Timer) ArrayList(java.util.ArrayList) LabelKey(io.opencensus.metrics.LabelKey) Metric(io.opencensus.metrics.export.Metric) Test(org.junit.Test)

Example 30 with Metric

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

the class DropWizardMetricsTest method collect_Meter.

@Test
public void collect_Meter() {
    Meter getRequests = metricRegistry.meter("get_requests");
    getRequests.mark();
    getRequests.mark();
    ArrayList<Metric> metrics = new ArrayList<>(dropWizardMetrics.getMetrics());
    assertThat(metrics.size()).isEqualTo(1);
    assertThat(metrics.get(0).getMetricDescriptor()).isEqualTo(MetricDescriptor.create("codahale_get_requests_meter", "Collected from codahale (metric=get_requests, " + "type=com.codahale.metrics.Meter)", DEFAULT_UNIT, Type.CUMULATIVE_INT64, Collections.<LabelKey>emptyList()));
    assertThat(metrics.get(0).getTimeSeriesList().size()).isEqualTo(1);
    assertThat(metrics.get(0).getTimeSeriesList().get(0).getLabelValues().size()).isEqualTo(0);
    assertThat(metrics.get(0).getTimeSeriesList().get(0).getPoints().size()).isEqualTo(1);
    assertThat(metrics.get(0).getTimeSeriesList().get(0).getPoints().get(0).getValue()).isEqualTo(Value.longValue(2));
    assertThat(metrics.get(0).getTimeSeriesList().get(0).getStartTimestamp()).isNotNull();
}
Also used : Meter(com.codahale.metrics.Meter) ArrayList(java.util.ArrayList) LabelKey(io.opencensus.metrics.LabelKey) Metric(io.opencensus.metrics.export.Metric) Test(org.junit.Test)

Aggregations

Metric (io.opencensus.metrics.export.Metric)73 Test (org.junit.Test)68 ArrayList (java.util.ArrayList)26 Timestamp (io.opencensus.common.Timestamp)19 TimeSeries (io.opencensus.metrics.export.TimeSeries)16 LabelKey (io.opencensus.metrics.LabelKey)15 LabelValue (io.opencensus.metrics.LabelValue)9 LongPoint (io.opencensus.metrics.LongGauge.LongPoint)9 DoublePoint (io.opencensus.metrics.DoubleGauge.DoublePoint)8 MetricDescriptor (io.opencensus.metrics.export.MetricDescriptor)8 DoublePoint (io.opencensus.metrics.DoubleCumulative.DoublePoint)6 LongPoint (io.opencensus.metrics.LongCumulative.LongPoint)6 DerivedLongGauge (io.opencensus.metrics.DerivedLongGauge)4 DerivedDoubleGauge (io.opencensus.metrics.DerivedDoubleGauge)3 LongGauge (io.opencensus.metrics.LongGauge)3 MetricName (io.dropwizard.metrics5.MetricName)2 DoubleGauge (io.opencensus.metrics.DoubleGauge)2 MetricProducer (io.opencensus.metrics.export.MetricProducer)2 Span (io.opencensus.trace.Span)2 Counter (com.codahale.metrics.Counter)1