use of com.yammer.metrics.core.WavefrontHistogram in project java by wavefrontHQ.
the class FlushProcessor method processHistogram.
@Override
public void processHistogram(MetricName name, Histogram histogram, FlushProcessorContext context) throws Exception {
if (histogram instanceof WavefrontHistogram && useWavefrontHistograms) {
WavefrontHistogram wavefrontHistogram = (WavefrontHistogram) histogram;
wavefront.report.Histogram.Builder builder = wavefront.report.Histogram.newBuilder();
builder.setBins(Lists.newLinkedList());
builder.setCounts(Lists.newLinkedList());
long minMillis = Long.MAX_VALUE;
if (wavefrontHistogram.count() == 0)
return;
for (WavefrontHistogram.MinuteBin minuteBin : wavefrontHistogram.bins(true)) {
builder.getBins().add(minuteBin.getDist().quantile(.5));
builder.getCounts().add(Math.toIntExact(minuteBin.getDist().size()));
minMillis = Long.min(minMillis, minuteBin.getMinMillis());
}
builder.setType(HistogramType.TDIGEST);
builder.setDuration(Math.toIntExact(currentMillis.get() - minMillis));
context.report(builder.build());
} else {
context.reportSubMetric(histogram.count(), "count");
for (Map.Entry<String, Double> entry : MetricsToTimeseries.explodeSummarizable(histogram, reportEmptyHistogramStats).entrySet()) {
context.reportSubMetric(entry.getValue(), entry.getKey());
}
for (Map.Entry<String, Double> entry : MetricsToTimeseries.explodeSampling(histogram, reportEmptyHistogramStats).entrySet()) {
context.reportSubMetric(entry.getValue(), entry.getKey());
}
histogram.clear();
}
sentCounter.inc();
}
use of com.yammer.metrics.core.WavefrontHistogram in project java by wavefrontHQ.
the class Main method main.
public static void main(String[] args) throws IOException, InterruptedException {
// Parse inputs.
System.out.println("Args: " + Joiner.on(", ").join(args));
if (args.length != 2) {
System.out.println("Usage: java -jar this.jar <metricsPort> <histogramsPort>");
return;
}
int port = Integer.parseInt(args[0]);
int histoPort = Integer.parseInt(args[1]);
// Set up periodic reporting.
MetricsRegistry metricsRegistry = new MetricsRegistry();
WavefrontYammerMetricsReporter wavefrontYammerMetricsReporter = new WavefrontYammerMetricsReporter(metricsRegistry, "wavefrontYammerMetrics", "localhost", port, histoPort, System::currentTimeMillis);
wavefrontYammerMetricsReporter.start(5, TimeUnit.SECONDS);
// Populate test metrics.
Counter counter = metricsRegistry.newCounter(new TaggedMetricName("group", "mycounter", "tag1", "value1"));
Histogram histogram = metricsRegistry.newHistogram(new TaggedMetricName("group2", "myhisto"), false);
WavefrontHistogram wavefrontHistogram = WavefrontHistogram.get(metricsRegistry, new TaggedMetricName("group", "mywavefronthisto", "tag2", "value2"));
while (true) {
counter.inc();
histogram.update(counter.count());
wavefrontHistogram.update(counter.count());
Thread.sleep(1000);
}
}
use of com.yammer.metrics.core.WavefrontHistogram in project java by wavefrontHQ.
the class SocketMetricsProcessor method processHistogram.
@Override
public void processHistogram(MetricName name, Histogram histogram, Void context) throws Exception {
if (histogram instanceof WavefrontHistogram) {
WavefrontHistogram wavefrontHistogram = (WavefrontHistogram) histogram;
List<WavefrontHistogram.MinuteBin> bins = wavefrontHistogram.bins(clear);
// don't send empty histograms.
if (bins.isEmpty())
return;
StringBuilder sb = new StringBuilder();
sb.append("!M ").append(timeSupplier.get() / 1000);
for (WavefrontHistogram.MinuteBin minuteBin : bins) {
sb.append(" #").append(minuteBin.getDist().size()).append(" ").append(minuteBin.getDist().quantile(.5));
}
sb.append(" \"").append(getName(name)).append("\"").append(tagsForMetricName(name)).append("\n");
histogramsSocket.write(sb.toString());
} else {
if (!sendEmptyHistograms && histogram.count() == 0) {
// send count still but skip the others.
writeMetric(name, "count", 0);
} else {
writeMetric(name, "count", histogram.count());
writeSampling(name, histogram);
writeSummarizable(name, histogram);
if (clear)
histogram.clear();
}
}
}
use of com.yammer.metrics.core.WavefrontHistogram in project java by wavefrontHQ.
the class JsonMetricsGeneratorTest method testWavefrontHistogramBulkUpdateHandlesNullParams.
@Test
public void testWavefrontHistogramBulkUpdateHandlesNullParams() throws IOException {
WavefrontHistogram wh = WavefrontHistogram.get(testRegistry, new MetricName("test", "", "metric"), time::get);
wh.bulkUpdate(null, ImmutableList.of(1, 5, 1));
wh.bulkUpdate(ImmutableList.of(15d, 30d, 45d, 100d), null);
wh.bulkUpdate(null, null);
String json = generate(false, false, false, null);
assertThat(json).isEqualTo("{\"test.metric\":{\"bins\":[]}}");
}
use of com.yammer.metrics.core.WavefrontHistogram in project java by wavefrontHQ.
the class JsonMetricsGeneratorTest method testWavefrontHistogramBulkUpdate.
@Test
public void testWavefrontHistogramBulkUpdate() throws IOException {
WavefrontHistogram wh = WavefrontHistogram.get(testRegistry, new MetricName("test", "", "metric"), time::get);
wh.bulkUpdate(ImmutableList.of(15d, 30d, 45d), ImmutableList.of(1, 5, 1));
// Simulate the 1 minute has passed and we are ready to flush the histogram
// (i.e. all the values prior to the current minute) over the wire...
time.addAndGet(60001L);
String json = generate(false, false, false, null);
assertThat(json).isEqualTo("{\"test.metric\":{\"bins\":[{\"count\":7,\"startMillis\":0,\"durationMillis\":60000,\"means\":[15.0,30.0,45.0],\"counts\":[1,5,1]}]}}");
}
Aggregations