Search in sources :

Example 1 with MeasureLong

use of io.opencensus.stats.Measure.MeasureLong in project ignite by apache.

the class OpenCensusMetricExporterSpi method export.

/**
 * {@inheritDoc}
 */
@Override
public void export() {
    StatsRecorder recorder = Stats.getStatsRecorder();
    try (Scope globalScope = tagScope()) {
        MeasureMap mmap = recorder.newMeasureMap();
        mreg.forEach(mreg -> {
            if (filter != null && !filter.test(mreg))
                return;
            mreg.forEach(metric -> {
                if (metric instanceof LongMetric || metric instanceof IntMetric || metric instanceof BooleanMetric || (metric instanceof ObjectMetric && ((ObjectMetric) metric).type() == Date.class) || (metric instanceof ObjectMetric && ((ObjectMetric) metric).type() == OffsetDateTime.class)) {
                    long val;
                    if (metric instanceof LongMetric)
                        val = ((LongMetric) metric).value();
                    else if (metric instanceof IntMetric)
                        val = ((IntMetric) metric).value();
                    else if (metric instanceof BooleanMetric)
                        val = ((BooleanMetric) metric).value() ? 1 : 0;
                    else if (metric instanceof ObjectMetric && ((ObjectMetric) metric).type() == Date.class)
                        val = ((ObjectMetric<Date>) metric).value().getTime();
                    else
                        val = ((ObjectMetric<OffsetDateTime>) metric).value().toInstant().toEpochMilli();
                    if (val < 0) {
                        if (log.isDebugEnabled())
                            log.debug("OpenCensus doesn't support negative values. Skip record of " + metric.name());
                        return;
                    }
                    MeasureLong msr = (MeasureLong) measures.computeIfAbsent(metric.name(), k -> createMeasure(metric, CREATE_LONG));
                    mmap.put(msr, val);
                } else if (metric instanceof DoubleMetric) {
                    double val = ((DoubleMetric) metric).value();
                    if (val < 0) {
                        if (log.isDebugEnabled())
                            log.debug("OpenCensus doesn't support negative values. Skip record of " + metric.name());
                        return;
                    }
                    MeasureDouble msr = (MeasureDouble) measures.computeIfAbsent(metric.name(), k -> createMeasure(metric, CREATE_DOUBLE));
                    mmap.put(msr, val);
                } else if (metric instanceof HistogramMetric) {
                    String[] names = histogramBucketNames((HistogramMetric) metric);
                    long[] vals = ((HistogramMetric) metric).value();
                    assert names.length == vals.length;
                    for (int i = 0; i < vals.length; i++) {
                        String name = names[i];
                        MeasureLong msr = (MeasureLong) measures.computeIfAbsent(name, k -> createMeasureLong(name, metric.description()));
                        mmap.put(msr, vals[i]);
                    }
                } else if (log.isDebugEnabled()) {
                    log.debug(metric.name() + "[" + metric.getClass() + "] not supported by Opencensus exporter");
                }
            });
        });
        mmap.record();
    }
}
Also used : StatsRecorder(io.opencensus.stats.StatsRecorder) TagContextBuilder(io.opencensus.tags.TagContextBuilder) StatsRecorder(io.opencensus.stats.StatsRecorder) IgniteSpiContext(org.apache.ignite.spi.IgniteSpiContext) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) Metric(org.apache.ignite.spi.metric.Metric) Stats(io.opencensus.stats.Stats) Date(java.util.Date) HashMap(java.util.HashMap) IgniteEx(org.apache.ignite.internal.IgniteEx) Function(java.util.function.Function) ObjectMetric(org.apache.ignite.spi.metric.ObjectMetric) ArrayList(java.util.ArrayList) PushMetricsExporterAdapter(org.apache.ignite.internal.processors.metric.PushMetricsExporterAdapter) Measure(io.opencensus.stats.Measure) MeasureDouble(io.opencensus.stats.Measure.MeasureDouble) MeasureMap(io.opencensus.stats.MeasureMap) Map(java.util.Map) TagMetadata(io.opencensus.tags.TagMetadata) TagValue(io.opencensus.tags.TagValue) View(io.opencensus.stats.View) ReadOnlyMetricManager(org.apache.ignite.spi.metric.ReadOnlyMetricManager) Tags(io.opencensus.tags.Tags) BooleanMetric(org.apache.ignite.spi.metric.BooleanMetric) HistogramMetric(org.apache.ignite.spi.metric.HistogramMetric) IntMetric(org.apache.ignite.spi.metric.IntMetric) Scope(io.opencensus.common.Scope) Name(io.opencensus.stats.View.Name) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) LastValue(io.opencensus.stats.Aggregation.LastValue) MeasureLong(io.opencensus.stats.Measure.MeasureLong) T2(org.apache.ignite.internal.util.typedef.T2) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) TagKey(io.opencensus.tags.TagKey) MetricUtils(org.apache.ignite.internal.processors.metric.impl.MetricUtils) UNLIMITED_PROPAGATION(io.opencensus.tags.TagMetadata.TagTtl.UNLIMITED_PROPAGATION) GridMetricManager(org.apache.ignite.internal.processors.metric.GridMetricManager) LongMetric(org.apache.ignite.spi.metric.LongMetric) DoubleMetric(org.apache.ignite.spi.metric.DoubleMetric) BooleanMetric(org.apache.ignite.spi.metric.BooleanMetric) HistogramMetric(org.apache.ignite.spi.metric.HistogramMetric) LongMetric(org.apache.ignite.spi.metric.LongMetric) MeasureDouble(io.opencensus.stats.Measure.MeasureDouble) MeasureMap(io.opencensus.stats.MeasureMap) Scope(io.opencensus.common.Scope) OffsetDateTime(java.time.OffsetDateTime) ObjectMetric(org.apache.ignite.spi.metric.ObjectMetric) MeasureLong(io.opencensus.stats.Measure.MeasureLong) DoubleMetric(org.apache.ignite.spi.metric.DoubleMetric) IntMetric(org.apache.ignite.spi.metric.IntMetric)

Example 2 with MeasureLong

use of io.opencensus.stats.Measure.MeasureLong in project ignite by apache.

the class OpenCensusMetricExporterSpi method createMeasureLong.

/**
 */
private MeasureLong createMeasureLong(String name, String desc) {
    MeasureLong msr = MeasureLong.create(name, desc == null ? name : desc, "");
    addView(msr);
    return msr;
}
Also used : MeasureLong(io.opencensus.stats.Measure.MeasureLong)

Example 3 with MeasureLong

use of io.opencensus.stats.Measure.MeasureLong in project instrumentation-java by census-instrumentation.

the class ViewManagerImplTest method preventRegisteringDifferentMeasureWithSameName.

@Test
public void preventRegisteringDifferentMeasureWithSameName() {
    MeasureDouble measure1 = MeasureDouble.create("measure", "description", "1");
    MeasureLong measure2 = MeasureLong.create("measure", "description", "1");
    View view1 = View.create(VIEW_NAME, VIEW_DESCRIPTION, measure1, DISTRIBUTION, Arrays.asList(KEY), CUMULATIVE);
    View view2 = View.create(VIEW_NAME_2, VIEW_DESCRIPTION, measure2, DISTRIBUTION, Arrays.asList(KEY), CUMULATIVE);
    testFailedToRegisterView(view1, view2, "A different measure with the same name is already registered");
}
Also used : MeasureLong(io.opencensus.stats.Measure.MeasureLong) MeasureDouble(io.opencensus.stats.Measure.MeasureDouble) View(io.opencensus.stats.View) Test(org.junit.Test)

Aggregations

MeasureLong (io.opencensus.stats.Measure.MeasureLong)3 MeasureDouble (io.opencensus.stats.Measure.MeasureDouble)2 View (io.opencensus.stats.View)2 Scope (io.opencensus.common.Scope)1 LastValue (io.opencensus.stats.Aggregation.LastValue)1 Measure (io.opencensus.stats.Measure)1 MeasureMap (io.opencensus.stats.MeasureMap)1 Stats (io.opencensus.stats.Stats)1 StatsRecorder (io.opencensus.stats.StatsRecorder)1 Name (io.opencensus.stats.View.Name)1 TagContextBuilder (io.opencensus.tags.TagContextBuilder)1 TagKey (io.opencensus.tags.TagKey)1 TagMetadata (io.opencensus.tags.TagMetadata)1 UNLIMITED_PROPAGATION (io.opencensus.tags.TagMetadata.TagTtl.UNLIMITED_PROPAGATION)1 TagValue (io.opencensus.tags.TagValue)1 Tags (io.opencensus.tags.Tags)1 OffsetDateTime (java.time.OffsetDateTime)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1