Search in sources :

Example 1 with Distribution

use of io.opencensus.stats.Aggregation.Distribution in project instrumentation-java by census-instrumentation.

the class AggregationTest method testCreateDistribution.

@Test
public void testCreateDistribution() {
    BucketBoundaries bucketBoundaries = BucketBoundaries.create(Arrays.asList(0.1, 2.2, 33.3));
    Distribution distribution = Distribution.create(bucketBoundaries);
    assertThat(distribution.getBucketBoundaries()).isEqualTo(bucketBoundaries);
}
Also used : Distribution(io.opencensus.stats.Aggregation.Distribution) Test(org.junit.Test)

Example 2 with Distribution

use of io.opencensus.stats.Aggregation.Distribution in project instrumentation-java by census-instrumentation.

the class StatszZPageHandler method emitViewDataTableHeader.

private static void emitViewDataTableHeader(View view, PrintWriter out, Formatter formatter) {
    out.write("<thead>");
    out.write("<tr>");
    for (TagKey tagKey : view.getColumns()) {
        formatter.format("<th class=\"borderRL\">TagKey: %s (string)</th>", tagKey.getName());
    }
    String unit = view.getMeasure().getUnit();
    view.getAggregation().match(new Function<Sum, Void>() {

        @Override
        public Void apply(Sum arg) {
            formatter.format("<th class=\"borderL\">%s, %s</th>", TABLE_HEADER_SUM, unit);
            return null;
        }
    }, new Function<Count, Void>() {

        @Override
        public Void apply(Count arg) {
            formatter.format("<th class=\"borderL\">%s</th>", TABLE_HEADER_COUNT);
            return null;
        }
    }, new Function<Distribution, Void>() {

        @Override
        public Void apply(Distribution arg) {
            formatter.format("<th>%s, %s</th>", TABLE_HEADER_MEAN, unit);
            formatter.format("<th class=\"borderL\">%s</th>", TABLE_HEADER_COUNT);
            formatter.format("<th class=\"borderL\">%s, %s</th>", TABLE_HEADER_MAX, unit);
            formatter.format("<th class=\"borderL\">%s, %s</th>", TABLE_HEADER_MIN, unit);
            formatter.format("<th class=\"borderL\">%s</th>", TABLE_HEADER_DEV);
            formatter.format("<th class=\"borderL\">%s</th>", TABLE_HEADER_HISTOGRAM);
            return null;
        }
    }, new Function<LastValue, Void>() {

        @Override
        public Void apply(LastValue arg) {
            formatter.format("<th class=\"borderL\">%s, %s</th>", TABLE_HEADER_LAST_VALUE, unit);
            return null;
        }
    }, new Function<Aggregation, Void>() {

        @Override
        public Void apply(Aggregation arg) {
            // deprecated RPC views.
            if (arg instanceof Aggregation.Mean) {
                formatter.format("<th>%s, %s</th>", TABLE_HEADER_MEAN, unit);
                formatter.format("<th class=\"borderL\">%s</th>", TABLE_HEADER_COUNT);
                return null;
            }
            throw new IllegalArgumentException("Unknown Aggregation.");
        }
    });
    out.write("</tr>");
    out.write("</thead>");
}
Also used : Sum(io.opencensus.stats.Aggregation.Sum) Count(io.opencensus.stats.Aggregation.Count) LastValue(io.opencensus.stats.Aggregation.LastValue) Aggregation(io.opencensus.stats.Aggregation) Distribution(io.opencensus.stats.Aggregation.Distribution) TagKey(io.opencensus.tags.TagKey)

Example 3 with Distribution

use of io.opencensus.stats.Aggregation.Distribution in project instrumentation-java by census-instrumentation.

the class StatszZPageHandler method emitViewDataRow.

private static void emitViewDataRow(View view, Entry<List</*@Nullable*/
TagValue>, AggregationData> entry, PrintWriter out, Formatter formatter) {
    out.write("<tr>");
    for (/*@Nullable*/
    TagValue tagValue : entry.getKey()) {
        String tagValueStr = tagValue == null ? "" : tagValue.asString();
        formatter.format("<td class=\"borderRL\">%s</td>", tagValueStr);
    }
    entry.getValue().match(new Function<SumDataDouble, Void>() {

        @Override
        public Void apply(SumDataDouble arg) {
            formatter.format("<td class=\"borderLL\">%.3f</td>", arg.getSum());
            return null;
        }
    }, new Function<SumDataLong, Void>() {

        @Override
        public Void apply(SumDataLong arg) {
            formatter.format("<td class=\"borderLL\">%d</td>", arg.getSum());
            return null;
        }
    }, new Function<CountData, Void>() {

        @Override
        public Void apply(CountData arg) {
            formatter.format("<td class=\"borderLL\">%d</td>", arg.getCount());
            return null;
        }
    }, new Function<DistributionData, Void>() {

        @Override
        public Void apply(DistributionData arg) {
            checkArgument(view.getAggregation() instanceof Distribution, "Distribution expected.");
            formatter.format("<td>%.3f</td>", arg.getMean());
            formatter.format("<td class=\"borderLL\">%d</td>", arg.getCount());
            formatter.format("<td class=\"borderLL\">%.3f</td>", arg.getMax());
            formatter.format("<td class=\"borderLL\">%.3f</td>", arg.getMin());
            formatter.format("<td class=\"borderLL\">%.3f</td>", arg.getSumOfSquaredDeviations());
            emitHistogramBuckets(((Distribution) view.getAggregation()).getBucketBoundaries().getBoundaries(), arg.getBucketCounts(), out, formatter);
            return null;
        }
    }, new Function<LastValueDataDouble, Void>() {

        @Override
        public Void apply(LastValueDataDouble arg) {
            formatter.format("<td>%.3f</td>", arg.getLastValue());
            return null;
        }
    }, new Function<LastValueDataLong, Void>() {

        @Override
        public Void apply(LastValueDataLong arg) {
            formatter.format("<td>%d</td>", arg.getLastValue());
            return null;
        }
    }, new Function<AggregationData, Void>() {

        @Override
        public Void apply(AggregationData arg) {
            if (arg instanceof AggregationData.MeanData) {
                AggregationData.MeanData meanData = (AggregationData.MeanData) arg;
                formatter.format("<td>%.3f</td>", meanData.getMean());
                formatter.format("<td class=\"borderLL\">%d</td>", meanData.getCount());
                return null;
            }
            throw new IllegalArgumentException("Unknown Aggregation.");
        }
    });
    out.write("</tr>");
}
Also used : SumDataLong(io.opencensus.stats.AggregationData.SumDataLong) CountData(io.opencensus.stats.AggregationData.CountData) AggregationData(io.opencensus.stats.AggregationData) LastValueDataDouble(io.opencensus.stats.AggregationData.LastValueDataDouble) DistributionData(io.opencensus.stats.AggregationData.DistributionData) Distribution(io.opencensus.stats.Aggregation.Distribution) SumDataDouble(io.opencensus.stats.AggregationData.SumDataDouble) TagValue(io.opencensus.tags.TagValue) LastValueDataLong(io.opencensus.stats.AggregationData.LastValueDataLong)

Aggregations

Distribution (io.opencensus.stats.Aggregation.Distribution)3 Aggregation (io.opencensus.stats.Aggregation)1 Count (io.opencensus.stats.Aggregation.Count)1 LastValue (io.opencensus.stats.Aggregation.LastValue)1 Sum (io.opencensus.stats.Aggregation.Sum)1 AggregationData (io.opencensus.stats.AggregationData)1 CountData (io.opencensus.stats.AggregationData.CountData)1 DistributionData (io.opencensus.stats.AggregationData.DistributionData)1 LastValueDataDouble (io.opencensus.stats.AggregationData.LastValueDataDouble)1 LastValueDataLong (io.opencensus.stats.AggregationData.LastValueDataLong)1 SumDataDouble (io.opencensus.stats.AggregationData.SumDataDouble)1 SumDataLong (io.opencensus.stats.AggregationData.SumDataLong)1 TagKey (io.opencensus.tags.TagKey)1 TagValue (io.opencensus.tags.TagValue)1 Test (org.junit.Test)1