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
}
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));
}
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));
}
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);
}
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);
}
}
Aggregations