Search in sources :

Example 1 with Histogram

use of wavefront.report.Histogram in project java by wavefrontHQ.

the class AccumulationTask method run.

@Override
public void run() {
    while (input.size() > 0 && !Thread.currentThread().isInterrupted()) {
        List<String> lines = input.peek();
        if (lines == null) {
            // remove corrupt data
            input.remove();
            continue;
        }
        long startNanos = nanoTime();
        for (String line : lines) {
            try {
                // Ignore empty lines
                if ((line = line.trim()).isEmpty()) {
                    continue;
                }
                // Parse line
                points.clear();
                try {
                    decoder.decodeReportPoints(line, points, "c");
                } catch (Exception e) {
                    final Throwable cause = Throwables.getRootCause(e);
                    String errMsg = "WF-300 Cannot parse: \"" + line + "\", reason: \"" + e.getMessage() + "\"";
                    if (cause != null && cause.getMessage() != null) {
                        errMsg = errMsg + ", root cause: \"" + cause.getMessage() + "\"";
                    }
                    throw new IllegalArgumentException(errMsg);
                }
                // now have the point, continue like in PointHandlerImpl
                ReportPoint event = points.get(0);
                // need the granularity here
                Validation.validatePoint(event, granularity.name(), line, validationLevel);
                if (event.getValue() instanceof Double) {
                    // Get key
                    Utils.HistogramKey histogramKey = Utils.makeKey(event, granularity);
                    double value = (Double) event.getValue();
                    eventCounter.inc();
                    // atomic update
                    digests.put(histogramKey, value, compression, ttlMillis);
                } else if (event.getValue() instanceof Histogram) {
                    Histogram value = (Histogram) event.getValue();
                    Utils.Granularity granularity = fromMillis(value.getDuration());
                    histogramBinCount.update(value.getCounts().size());
                    histogramSampleCount.update(value.getCounts().stream().mapToLong(x -> x).sum());
                    // Key
                    Utils.HistogramKey histogramKey = Utils.makeKey(event, granularity);
                    histogramCounter.inc();
                    // atomic update
                    digests.put(histogramKey, value, compression, ttlMillis);
                }
            } catch (Exception e) {
                if (!(e instanceof IllegalArgumentException)) {
                    logger.log(Level.SEVERE, "Unexpected error while parsing/accumulating sample: " + e.getMessage(), e);
                }
                ignoredCounter.inc();
                if (StringUtils.isNotEmpty(e.getMessage())) {
                    blockedPointsHandler.handleBlockedPoint(e.getMessage());
                }
            }
        }
        // end point processing
        input.remove();
        batchProcessTime.update(nanoTime() - startNanos);
    }
// end batch processing
}
Also used : PointHandler(com.wavefront.agent.PointHandler) StringUtils(org.apache.commons.lang.StringUtils) Counter(com.yammer.metrics.core.Counter) Validation(com.wavefront.agent.Validation) Throwables(com.google.common.base.Throwables) ObjectQueue(com.squareup.tape.ObjectQueue) AgentDigest(com.tdunning.math.stats.AgentDigest) Logger(java.util.logging.Logger) Level(java.util.logging.Level) System.nanoTime(java.lang.System.nanoTime) List(java.util.List) Lists(com.google.common.collect.Lists) Utils(com.wavefront.agent.histogram.Utils) MetricName(com.yammer.metrics.core.MetricName) ReportPoint(wavefront.report.ReportPoint) Decoder(com.wavefront.ingester.Decoder) Metrics(com.yammer.metrics.Metrics) Histogram(wavefront.report.Histogram) Granularity.fromMillis(com.wavefront.agent.histogram.Utils.Granularity.fromMillis) Histogram(wavefront.report.Histogram) StringUtils(org.apache.commons.lang.StringUtils) Utils(com.wavefront.agent.histogram.Utils) ReportPoint(wavefront.report.ReportPoint)

Example 2 with Histogram

use of wavefront.report.Histogram in project java by wavefrontHQ.

the class LogsIngesterTest method testWavefrontHistogram.

@Test
public void testWavefrontHistogram() throws Exception {
    setup("histos.yml");
    String[] lines = new String[100];
    for (int i = 1; i < 101; i++) {
        lines[i - 1] = "histo " + i;
    }
    ReportPoint reportPoint = getPoints(1, lines).get(0);
    assertThat(reportPoint.getValue(), instanceOf(Histogram.class));
    Histogram wavefrontHistogram = (Histogram) reportPoint.getValue();
    assertThat(wavefrontHistogram.getBins(), hasSize(1));
    assertThat(wavefrontHistogram.getBins(), contains(50.5));
    assertThat(wavefrontHistogram.getCounts(), hasSize(1));
    assertThat(wavefrontHistogram.getCounts(), contains(100));
}
Also used : Histogram(wavefront.report.Histogram) ReportPoint(wavefront.report.ReportPoint) ReportPoint(wavefront.report.ReportPoint) Test(org.junit.Test)

Example 3 with Histogram

use of wavefront.report.Histogram in project java by wavefrontHQ.

the class LogsIngesterTest method testWavefrontHistogramMultipleCentroids.

@Test
public void testWavefrontHistogramMultipleCentroids() throws Exception {
    setup("histos.yml");
    String[] lines = new String[60];
    for (int i = 1; i < 61; i++) {
        lines[i - 1] = "histo " + i;
    }
    ReportPoint reportPoint = getPoints(1, 1000, this::receiveLog, lines).get(0);
    assertThat(reportPoint.getValue(), instanceOf(Histogram.class));
    Histogram wavefrontHistogram = (Histogram) reportPoint.getValue();
    assertThat(wavefrontHistogram.getBins(), hasSize(2));
    assertThat(wavefrontHistogram.getCounts(), hasSize(2));
    assertThat(wavefrontHistogram.getCounts().stream().reduce(Integer::sum).get(), equalTo(60));
}
Also used : Histogram(wavefront.report.Histogram) ReportPoint(wavefront.report.ReportPoint) ReportPoint(wavefront.report.ReportPoint) Test(org.junit.Test)

Example 4 with Histogram

use of wavefront.report.Histogram in project java by wavefrontHQ.

the class JsonMetricsParserTest method testWavefrontHistogram.

@Test
public void testWavefrontHistogram() throws IOException {
    JsonNode node = factory.createParser("{\"test.metric\":{\"bins\":[{\"count\":2,\"startMillis\":0,\"durationMillis\":60000,\"means\":[10.0,100.0],\"counts\":[1,1]},{\"count\":1,\"startMillis\":60000,\"durationMillis\":60000,\"means\":[1000.0],\"counts\":[1]}]}}").readValueAsTree();
    report("customer", "path", node, points, "host", 100L);
    assertThat(points).hasSize(2);
    assertThat(points.get(0).getMetric()).isEqualTo("path.test.metric");
    assertThat(points.get(0).getValue()).isInstanceOf(Histogram.class);
    assertThat(((Histogram) points.get(0).getValue()).getDuration()).isEqualTo(60000L);
    assertThat(((Histogram) points.get(0).getValue()).getBins()).isEqualTo(newArrayList(10.0, 100.0));
    assertThat(((Histogram) points.get(0).getValue()).getCounts()).isEqualTo(newArrayList(1, 1));
    assertThat(points.get(0).getHost()).isEqualTo("host");
    assertThat(points.get(0).getTable()).isEqualTo("customer");
    assertThat(points.get(0).getTimestamp()).isEqualTo(0L);
    assertThat(points.get(1).getMetric()).isEqualTo("path.test.metric");
    assertThat(points.get(1).getValue()).isInstanceOf(Histogram.class);
    assertThat(((Histogram) points.get(1).getValue()).getDuration()).isEqualTo(60000L);
    assertThat(((Histogram) points.get(1).getValue()).getBins()).isEqualTo(newArrayList(1000.0));
    assertThat(((Histogram) points.get(1).getValue()).getCounts()).isEqualTo(newArrayList(1));
    assertThat(points.get(1).getHost()).isEqualTo("host");
    assertThat(points.get(1).getTable()).isEqualTo("customer");
    assertThat(points.get(1).getTimestamp()).isEqualTo(60000L);
}
Also used : Histogram(wavefront.report.Histogram) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Example 5 with Histogram

use of wavefront.report.Histogram in project java by wavefrontHQ.

the class PointHandlerLoggingDecorator method countPoint.

private void countPoint(ReportPoint point) {
    if (point.getValue() instanceof Histogram) {
        Histogram h = (Histogram) point.getValue();
        numHistogramPointsReported.addAndGet(1);
        numHistogramSamplesReported.addAndGet(h.getCounts().stream().mapToLong(Integer::longValue).sum());
    } else {
        numScalarPointsReported.addAndGet(1);
    }
}
Also used : Histogram(wavefront.report.Histogram)

Aggregations

Histogram (wavefront.report.Histogram)14 Test (org.junit.Test)10 ReportPoint (wavefront.report.ReportPoint)10 ArrayList (java.util.ArrayList)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Throwables (com.google.common.base.Throwables)1 Lists (com.google.common.collect.Lists)1 ObjectQueue (com.squareup.tape.ObjectQueue)1 AgentDigest (com.tdunning.math.stats.AgentDigest)1 PointHandler (com.wavefront.agent.PointHandler)1 PointHandlerImpl.pointToString (com.wavefront.agent.PointHandlerImpl.pointToString)1 Validation (com.wavefront.agent.Validation)1 Utils (com.wavefront.agent.histogram.Utils)1 Granularity.fromMillis (com.wavefront.agent.histogram.Utils.Granularity.fromMillis)1 Decoder (com.wavefront.ingester.Decoder)1 Metrics (com.yammer.metrics.Metrics)1 Counter (com.yammer.metrics.core.Counter)1 MetricName (com.yammer.metrics.core.MetricName)1 System.nanoTime (java.lang.System.nanoTime)1 List (java.util.List)1