Search in sources :

Example 1 with MetricDescriptor

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

the class LongGaugeImplTest method withConstantLabels.

@Test
public void withConstantLabels() {
    List<LabelKey> labelKeys = Arrays.asList(LabelKey.create("key1", "desc"), LabelKey.create("key2", "desc"));
    List<LabelValue> labelValues = Arrays.asList(LabelValue.create("value1"), LabelValue.create("value2"));
    LabelKey constantKey = LabelKey.create("constant_key", "desc");
    LabelValue constantValue = LabelValue.create("constant_value");
    Map<LabelKey, LabelValue> constantLabels = Collections.<LabelKey, LabelValue>singletonMap(constantKey, constantValue);
    LongGaugeImpl longGauge = new LongGaugeImpl(METRIC_NAME, METRIC_DESCRIPTION, METRIC_UNIT, labelKeys, constantLabels);
    LongPoint longPoint = longGauge.getOrCreateTimeSeries(labelValues);
    longPoint.add(1);
    longPoint.add(2);
    LongPoint defaultPoint = longGauge.getDefaultTimeSeries();
    defaultPoint.set(100);
    List<LabelKey> allKeys = new ArrayList<>(labelKeys);
    allKeys.add(constantKey);
    MetricDescriptor expectedDescriptor = MetricDescriptor.create(METRIC_NAME, METRIC_DESCRIPTION, METRIC_UNIT, Type.GAUGE_INT64, allKeys);
    List<LabelValue> allValues = new ArrayList<>(labelValues);
    allValues.add(constantValue);
    List<TimeSeries> expectedTimeSeriesList = new ArrayList<TimeSeries>();
    TimeSeries defaultTimeSeries = TimeSeries.createWithOnePoint(Arrays.asList(UNSET_VALUE, UNSET_VALUE, constantValue), Point.create(Value.longValue(100), TEST_TIME), null);
    expectedTimeSeriesList.add(TimeSeries.createWithOnePoint(allValues, Point.create(Value.longValue(3), TEST_TIME), null));
    expectedTimeSeriesList.add(defaultTimeSeries);
    Metric metric = longGauge.getMetric(testClock);
    assertThat(metric).isNotNull();
    assertThat(metric.getMetricDescriptor()).isEqualTo(expectedDescriptor);
    assertThat(metric.getTimeSeriesList().size()).isEqualTo(2);
    assertThat(metric.getTimeSeriesList()).containsExactlyElementsIn(expectedTimeSeriesList);
    longGauge.removeTimeSeries(labelValues);
    Metric metric2 = longGauge.getMetric(testClock);
    assertThat(metric2).isNotNull();
    assertThat(metric2.getTimeSeriesList()).containsExactly(defaultTimeSeries);
}
Also used : MetricDescriptor(io.opencensus.metrics.export.MetricDescriptor) TimeSeries(io.opencensus.metrics.export.TimeSeries) LabelValue(io.opencensus.metrics.LabelValue) ArrayList(java.util.ArrayList) LabelKey(io.opencensus.metrics.LabelKey) Metric(io.opencensus.metrics.export.Metric) LongPoint(io.opencensus.metrics.LongGauge.LongPoint) Test(org.junit.Test)

Example 2 with MetricDescriptor

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

the class MetricUtilsTest method viewToMetricDescriptor_Count.

@Test
public void viewToMetricDescriptor_Count() {
    MetricDescriptor metricDescriptor = MetricUtils.viewToMetricDescriptor(VIEW_3);
    assertThat(metricDescriptor).isNotNull();
    assertThat(metricDescriptor.getName()).isEqualTo(VIEW_NAME.asString());
    assertThat(metricDescriptor.getUnit()).isEqualTo(MetricUtils.COUNT_UNIT);
    assertThat(metricDescriptor.getType()).isEqualTo(Type.CUMULATIVE_INT64);
    assertThat(metricDescriptor.getDescription()).isEqualTo(VIEW_DESCRIPTION);
    assertThat(metricDescriptor.getLabelKeys()).containsExactly(LabelKey.create(KEY.getName(), ""));
}
Also used : MetricDescriptor(io.opencensus.metrics.export.MetricDescriptor) Test(org.junit.Test)

Example 3 with MetricDescriptor

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

the class DropWizardMetrics method collectCounter.

/**
 * Returns a {@code Metric} collected from {@link Counter}.
 *
 * @param dropwizardName the metric name.
 * @param counter the counter object to collect.
 * @return a {@code Metric}.
 */
private Metric collectCounter(String dropwizardName, Counter counter) {
    String metricName = DropWizardUtils.generateFullMetricName(dropwizardName, "counter");
    String metricDescription = DropWizardUtils.generateFullMetricDescription(dropwizardName, counter);
    MetricDescriptor metricDescriptor = MetricDescriptor.create(metricName, metricDescription, DEFAULT_UNIT, Type.GAUGE_INT64, Collections.<LabelKey>emptyList());
    TimeSeries timeSeries = TimeSeries.createWithOnePoint(Collections.<LabelValue>emptyList(), Point.create(Value.longValue(counter.getCount()), clock.now()), null);
    return Metric.createWithOneTimeSeries(metricDescriptor, timeSeries);
}
Also used : MetricDescriptor(io.opencensus.metrics.export.MetricDescriptor) TimeSeries(io.opencensus.metrics.export.TimeSeries)

Example 4 with MetricDescriptor

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

the class DropWizardMetrics method collectMeter.

/**
 * Returns a {@code Metric} collected from {@link Meter}.
 *
 * @param dropwizardName the metric name.
 * @param meter the meter object to collect
 * @return a {@code Metric}.
 */
private Metric collectMeter(String dropwizardName, Meter meter) {
    String metricName = DropWizardUtils.generateFullMetricName(dropwizardName, "meter");
    String metricDescription = DropWizardUtils.generateFullMetricDescription(dropwizardName, meter);
    MetricDescriptor metricDescriptor = MetricDescriptor.create(metricName, metricDescription, DEFAULT_UNIT, Type.CUMULATIVE_INT64, Collections.<LabelKey>emptyList());
    TimeSeries timeSeries = TimeSeries.createWithOnePoint(Collections.<LabelValue>emptyList(), Point.create(Value.longValue(meter.getCount()), clock.now()), cumulativeStartTimestamp);
    return Metric.createWithOneTimeSeries(metricDescriptor, timeSeries);
}
Also used : MetricDescriptor(io.opencensus.metrics.export.MetricDescriptor) TimeSeries(io.opencensus.metrics.export.TimeSeries)

Example 5 with MetricDescriptor

use of io.opencensus.metrics.export.MetricDescriptor 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)

Aggregations

MetricDescriptor (io.opencensus.metrics.export.MetricDescriptor)21 TimeSeries (io.opencensus.metrics.export.TimeSeries)17 ArrayList (java.util.ArrayList)11 Test (org.junit.Test)11 LabelValue (io.opencensus.metrics.LabelValue)10 LabelKey (io.opencensus.metrics.LabelKey)8 Metric (io.opencensus.metrics.export.Metric)8 Timestamp (io.opencensus.common.Timestamp)4 Point (io.opencensus.metrics.export.Point)3 AbstractMap (java.util.AbstractMap)3 List (java.util.List)3 Type (io.opencensus.metrics.export.MetricDescriptor.Type)2 Snapshot (io.opencensus.metrics.export.Summary.Snapshot)2 ValueAtPercentile (io.opencensus.metrics.export.Summary.Snapshot.ValueAtPercentile)2 Value (io.opencensus.metrics.export.Value)2 Nullable (javax.annotation.Nullable)2 DataPoint (com.signalfx.metrics.protobuf.SignalFxProtocolBuffers.DataPoint)1 MetricType (com.signalfx.metrics.protobuf.SignalFxProtocolBuffers.MetricType)1 DoublePoint (io.opencensus.metrics.DoubleCumulative.DoublePoint)1 DoublePoint (io.opencensus.metrics.DoubleGauge.DoublePoint)1