Search in sources :

Example 1 with AggregationData

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

the class StatszZPageHandlerTest method assertContainsViewData.

private static void assertContainsViewData(OutputStream output, ViewData viewData) {
    View view = viewData.getView();
    assertThat(output.toString()).contains(view.getName().asString());
    assertThat(output.toString()).contains(view.getDescription());
    assertThat(output.toString()).contains(view.getMeasure().getName());
    for (TagKey tagKey : view.getColumns()) {
        assertThat(output.toString()).contains(tagKey.getName());
    }
    String aggregationType = view.getAggregation().match(Functions.returnConstant("Sum"), Functions.returnConstant("Count"), Functions.returnConstant("Distribution"), Functions.returnConstant("Last Value"), new Function<Aggregation, String>() {

        @Override
        public String apply(Aggregation arg) {
            if (arg instanceof Aggregation.Mean) {
                return "Mean";
            }
            throw new AssertionError();
        }
    });
    assertThat(output.toString()).contains(aggregationType);
    for (Map.Entry<List<TagValue>, AggregationData> /*@Nullable*/
    entry : viewData.getAggregationMap().entrySet()) {
        List<TagValue> tagValues = entry.getKey();
        for (TagValue tagValue : tagValues) {
            String tagValueStr = tagValue == null ? "" : tagValue.asString();
            assertThat(output.toString()).contains(tagValueStr);
        }
        entry.getValue().match(Functions.</*@Nullable*/
        Void>throwAssertionError(), Functions.</*@Nullable*/
        Void>throwAssertionError(), Functions.</*@Nullable*/
        Void>throwAssertionError(), new Function<AggregationData.DistributionData, Void>() {

            @Override
            public Void apply(AggregationData.DistributionData arg) {
                assertThat(output.toString()).contains(String.valueOf(arg.getCount()));
                assertThat(output.toString()).contains(String.valueOf(arg.getMax()));
                assertThat(output.toString()).contains(String.valueOf(arg.getMin()));
                assertThat(output.toString()).contains(String.valueOf(arg.getMean()));
                assertThat(output.toString()).contains(String.valueOf(arg.getSumOfSquaredDeviations()));
                return null;
            }
        }, Functions.</*@Nullable*/
        Void>throwAssertionError(), Functions.</*@Nullable*/
        Void>throwAssertionError(), new Function<AggregationData, Void>() {

            @Override
            public Void apply(AggregationData arg) {
                if (arg instanceof MeanData) {
                    MeanData meanData = (MeanData) arg;
                    assertThat(output.toString()).contains(String.valueOf(meanData.getCount()));
                    assertThat(output.toString()).contains(String.valueOf(meanData.getMean()));
                    return null;
                }
                throw new AssertionError();
            }
        });
    }
}
Also used : AggregationData(io.opencensus.stats.AggregationData) MeanData(io.opencensus.stats.AggregationData.MeanData) View(io.opencensus.stats.View) Aggregation(io.opencensus.stats.Aggregation) TagKey(io.opencensus.tags.TagKey) List(java.util.List) TagValue(io.opencensus.tags.TagValue) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 2 with AggregationData

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

the class RpczZPageHandler method getStatsSnapshots.

private void getStatsSnapshots(Map<String, StatsSnapshot> map, List<View> views) {
    for (View view : views) {
        ViewData viewData = viewManager.getView(view.getName());
        if (viewData == null) {
            continue;
        }
        for (Entry<List<TagValue>, AggregationData> /*@Nullable*/
        entry : viewData.getAggregationMap().entrySet()) {
            TagValue tagValue;
            List<TagValue> /*@Nullable*/
            tagValues = entry.getKey();
            if (tagValues.size() == 1) {
                tagValue = tagValues.get(0);
            } else {
                // Error count views have two tag key: status and method.
                tagValue = tagValues.get(1);
            }
            String method = tagValue == null ? "" : tagValue.asString();
            StatsSnapshot snapshot = map.get(method);
            if (snapshot == null) {
                snapshot = new StatsSnapshot();
                map.put(method, snapshot);
            }
            getStats(snapshot, entry.getValue(), view, viewData.getWindowData());
        }
    }
}
Also used : ViewData(io.opencensus.stats.ViewData) AggregationData(io.opencensus.stats.AggregationData) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) TagValue(io.opencensus.tags.TagValue) View(io.opencensus.stats.View)

Example 3 with AggregationData

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

the class RpczZPageHandler method getStats.

// Gets RPC stats by its view definition, and set it to stats snapshot.
private static void getStats(StatsSnapshot snapshot, AggregationData data, View view, ViewData.AggregationWindowData windowData) {
    if (view == RPC_CLIENT_ROUNDTRIP_LATENCY_VIEW || view == RPC_SERVER_SERVER_LATENCY_VIEW) {
        snapshot.avgLatencyTotal = ((DistributionData) data).getMean();
    } else if (view == RPC_CLIENT_ROUNDTRIP_LATENCY_MINUTE_VIEW || view == RPC_SERVER_SERVER_LATENCY_MINUTE_VIEW) {
        snapshot.avgLatencyLastMinute = ((AggregationData.MeanData) data).getMean();
    } else if (view == RPC_CLIENT_ROUNDTRIP_LATENCY_HOUR_VIEW || view == RPC_SERVER_SERVER_LATENCY_HOUR_VIEW) {
        snapshot.avgLatencyLastHour = ((AggregationData.MeanData) data).getMean();
    } else if (view == RPC_CLIENT_ERROR_COUNT_VIEW || view == RPC_SERVER_ERROR_COUNT_VIEW) {
        snapshot.errorsTotal = ((AggregationData.MeanData) data).getCount();
    } else if (view == RPC_CLIENT_ERROR_COUNT_MINUTE_VIEW || view == RPC_SERVER_ERROR_COUNT_MINUTE_VIEW) {
        snapshot.errorsLastMinute = ((AggregationData.MeanData) data).getCount();
    } else if (view == RPC_CLIENT_ERROR_COUNT_HOUR_VIEW || view == RPC_SERVER_ERROR_COUNT_HOUR_VIEW) {
        snapshot.errorsLastHour = ((AggregationData.MeanData) data).getCount();
    } else if (view == RPC_CLIENT_REQUEST_BYTES_VIEW || view == RPC_SERVER_REQUEST_BYTES_VIEW) {
        DistributionData distributionData = (DistributionData) data;
        snapshot.inputRateTotal = distributionData.getCount() * distributionData.getMean() / BYTES_PER_KB / getDurationInSecs((ViewData.AggregationWindowData.CumulativeData) windowData);
    } else if (view == RPC_CLIENT_REQUEST_BYTES_MINUTE_VIEW || view == RPC_SERVER_REQUEST_BYTES_MINUTE_VIEW) {
        AggregationData.MeanData meanData = (AggregationData.MeanData) data;
        snapshot.inputRateLastMinute = meanData.getMean() * meanData.getCount() / BYTES_PER_KB / SECONDS_PER_MINUTE;
    } else if (view == RPC_CLIENT_REQUEST_BYTES_HOUR_VIEW || view == RPC_SERVER_REQUEST_BYTES_HOUR_VIEW) {
        AggregationData.MeanData meanData = (AggregationData.MeanData) data;
        snapshot.inputRateLastHour = meanData.getMean() * meanData.getCount() / BYTES_PER_KB / SECONDS_PER_HOUR;
    } else if (view == RPC_CLIENT_RESPONSE_BYTES_VIEW || view == RPC_SERVER_RESPONSE_BYTES_VIEW) {
        DistributionData distributionData = (DistributionData) data;
        snapshot.outputRateTotal = distributionData.getCount() * distributionData.getMean() / BYTES_PER_KB / getDurationInSecs((ViewData.AggregationWindowData.CumulativeData) windowData);
    } else if (view == RPC_CLIENT_RESPONSE_BYTES_MINUTE_VIEW || view == RPC_SERVER_RESPONSE_BYTES_MINUTE_VIEW) {
        AggregationData.MeanData meanData = (AggregationData.MeanData) data;
        snapshot.outputRateLastMinute = meanData.getMean() * meanData.getCount() / BYTES_PER_KB / SECONDS_PER_MINUTE;
    } else if (view == RPC_CLIENT_RESPONSE_BYTES_HOUR_VIEW || view == RPC_SERVER_RESPONSE_BYTES_HOUR_VIEW) {
        AggregationData.MeanData meanData = (AggregationData.MeanData) data;
        snapshot.outputRateLastHour = meanData.getMean() * meanData.getCount() / BYTES_PER_KB / SECONDS_PER_HOUR;
    } else if (view == RPC_CLIENT_STARTED_COUNT_MINUTE_VIEW || view == RPC_SERVER_STARTED_COUNT_MINUTE_VIEW) {
        snapshot.countLastMinute = ((CountData) data).getCount();
        snapshot.rpcRateLastMinute = snapshot.countLastMinute / SECONDS_PER_MINUTE;
    } else if (view == RPC_CLIENT_STARTED_COUNT_HOUR_VIEW || view == RPC_SERVER_STARTED_COUNT_HOUR_VIEW) {
        snapshot.countLastHour = ((CountData) data).getCount();
        snapshot.rpcRateLastHour = snapshot.countLastHour / SECONDS_PER_HOUR;
    } else if (view == RPC_CLIENT_STARTED_COUNT_CUMULATIVE_VIEW || view == RPC_SERVER_STARTED_COUNT_CUMULATIVE_VIEW) {
        snapshot.countTotal = ((CountData) data).getCount();
        snapshot.rpcRateTotal = snapshot.countTotal / getDurationInSecs((ViewData.AggregationWindowData.CumulativeData) windowData);
    }
// TODO(songya): compute and store latency percentiles.
}
Also used : DistributionData(io.opencensus.stats.AggregationData.DistributionData) AggregationData(io.opencensus.stats.AggregationData) ViewData(io.opencensus.stats.ViewData) CountData(io.opencensus.stats.AggregationData.CountData)

Example 4 with AggregationData

use of io.opencensus.stats.AggregationData 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)

Example 5 with AggregationData

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

the class StatszZPageHandler method emitViewData.

private static void emitViewData(/*@Nullable*/
ViewData viewData, View.Name viewName, PrintWriter out, Formatter formatter) {
    if (viewData == null) {
        formatter.format("<p class=\"view\">No Stats found for View %s.</p>", viewName.asString());
        return;
    }
    View view = viewData.getView();
    emitViewInfo(view, viewData.getWindowData(), out, formatter);
    formatter.format("<p class=\"view\">Stats for View: %s</p>", view.getName().asString());
    formatter.format("<table cellspacing=0 cellpadding=0>");
    emitViewDataTableHeader(view, out, formatter);
    for (Entry<List<TagValue>, AggregationData> /*@Nullable*/
    entry : viewData.getAggregationMap().entrySet()) {
        emitViewDataRow(view, entry, out, formatter);
    }
    out.write("</table>");
    out.write("<p></p>");
}
Also used : AggregationData(io.opencensus.stats.AggregationData) List(java.util.List) View(io.opencensus.stats.View)

Aggregations

AggregationData (io.opencensus.stats.AggregationData)5 View (io.opencensus.stats.View)3 TagValue (io.opencensus.tags.TagValue)3 List (java.util.List)3 CountData (io.opencensus.stats.AggregationData.CountData)2 DistributionData (io.opencensus.stats.AggregationData.DistributionData)2 ViewData (io.opencensus.stats.ViewData)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Aggregation (io.opencensus.stats.Aggregation)1 Distribution (io.opencensus.stats.Aggregation.Distribution)1 LastValueDataDouble (io.opencensus.stats.AggregationData.LastValueDataDouble)1 LastValueDataLong (io.opencensus.stats.AggregationData.LastValueDataLong)1 MeanData (io.opencensus.stats.AggregationData.MeanData)1 SumDataDouble (io.opencensus.stats.AggregationData.SumDataDouble)1 SumDataLong (io.opencensus.stats.AggregationData.SumDataLong)1 TagKey (io.opencensus.tags.TagKey)1 Map (java.util.Map)1