use of com.wavefront.agent.histogram.Utils.HistogramKey in project java by wavefrontHQ.
the class PushAgent method startHistogramListeners.
protected void startHistogramListeners(Iterator<String> ports, Decoder<String> decoder, PointHandler pointHandler, TapeDeck<List<String>> receiveDeck, String listenerBinType, int flushSecs, int fanout, boolean memoryCacheEnabled, File baseDirectory, Long accumulatorSize, int avgKeyBytes, int avgDigestBytes, short compression) {
// Accumulator
MapLoader<HistogramKey, AgentDigest, HistogramKeyMarshaller, AgentDigestMarshaller> mapLoader = new MapLoader<>(HistogramKey.class, AgentDigest.class, accumulatorSize, avgKeyBytes, avgDigestBytes, HistogramKeyMarshaller.get(), AgentDigestMarshaller.get(), persistAccumulator);
File accumulationFile = new File(baseDirectory, "accumulator." + listenerBinType);
ChronicleMap<HistogramKey, AgentDigest> accumulator = mapLoader.get(accumulationFile);
histogramExecutor.scheduleWithFixedDelay(() -> {
// warn if accumulator is more than 1.5x the original size, as ChronicleMap starts losing efficiency
if (accumulator.size() > accumulatorSize * 1.5) {
logger.warning("Histogram " + listenerBinType + " accumulator size (" + accumulator.size() + ") is much higher than configured size (" + accumulatorSize + "), proxy may experience performance issues or crash!");
}
}, 10, 10, TimeUnit.SECONDS);
AccumulationCache cachedAccumulator = new AccumulationCache(accumulator, (memoryCacheEnabled ? accumulatorSize : 0), null);
// Schedule write-backs
histogramExecutor.scheduleWithFixedDelay(cachedAccumulator.getResolveTask(), histogramAccumulatorResolveInterval, histogramAccumulatorResolveInterval, TimeUnit.MILLISECONDS);
PointHandlerDispatcher dispatcher = new PointHandlerDispatcher(cachedAccumulator, pointHandler, histogramAccumulatorFlushMaxBatchSize < 0 ? null : histogramAccumulatorFlushMaxBatchSize);
histogramExecutor.scheduleWithFixedDelay(dispatcher, histogramAccumulatorFlushInterval, histogramAccumulatorFlushInterval, TimeUnit.MILLISECONDS);
// gracefully shutdown persisted accumulator (ChronicleMap) on proxy exit
shutdownTasks.add(() -> {
try {
logger.fine("Flushing in-flight histogram accumulator digests: " + listenerBinType);
cachedAccumulator.getResolveTask().run();
logger.fine("Shutting down histogram accumulator cache: " + listenerBinType);
accumulator.close();
} catch (Throwable t) {
logger.log(Level.SEVERE, "Error flushing " + listenerBinType + " accumulator, possibly unclean shutdown: ", t);
}
});
ports.forEachRemaining(port -> {
startHistogramListener(port, decoder, pointHandler, cachedAccumulator, baseDirectory, (listenerBinType.equals("minute") ? Utils.Granularity.MINUTE : (listenerBinType.equals("hour") ? Utils.Granularity.HOUR : Utils.Granularity.DAY)), receiveDeck, TimeUnit.SECONDS.toMillis(flushSecs), fanout, compression);
logger.info("listening on port: " + port + " for histogram samples, accumulating to the " + listenerBinType);
});
}
use of com.wavefront.agent.histogram.Utils.HistogramKey in project java by wavefrontHQ.
the class MapLoaderTest method testCorruptedFileFallsBackToInMemory.
// NOTE: Chronicle's repair attempt takes >1min for whatever reason.
@Ignore
@Test
public void testCorruptedFileFallsBackToInMemory() throws IOException {
FileOutputStream fos = new FileOutputStream(file);
fos.write("Nonsense".getBytes());
fos.flush();
ConcurrentMap<HistogramKey, AgentDigest> map = loader.get(file);
assertThat(((VanillaChronicleMap) map).file()).isNull();
testPutRemove(map);
}
use of com.wavefront.agent.histogram.Utils.HistogramKey in project java by wavefrontHQ.
the class AccumulationTaskTest method testMultipleTimes.
@Test
public void testMultipleTimes() {
in.add(ImmutableList.of("min0 1 " + (DEFAULT_TIME_MILLIS - 60000), "min0 1 " + (DEFAULT_TIME_MILLIS - 60000), "min1 1 " + DEFAULT_TIME_MILLIS));
eventSubject.run();
cache.getResolveTask().run();
HistogramKey min0 = Utils.makeKey(ReportPoint.newBuilder().setMetric("min0").setTimestamp(DEFAULT_TIME_MILLIS - 60000).setValue(1).build(), MINUTE);
HistogramKey min1 = Utils.makeKey(ReportPoint.newBuilder().setMetric("min1").setTimestamp(DEFAULT_TIME_MILLIS).setValue(1).build(), MINUTE);
assertThat(badPointsOut).hasSize(0);
assertThat(out.get(min0)).isNotNull();
assertThat(out.get(min0).size()).isEqualTo(2);
assertThat(out.get(min1)).isNotNull();
assertThat(out.get(min1).size()).isEqualTo(1);
}
Aggregations