use of com.yammer.metrics.core.Histogram 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.Histogram 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.Histogram in project java by wavefrontHQ.
the class WavefrontYammerMetricsReporterTest method testPlainHistogramWithoutClear.
@Test(timeout = 1000)
public void testPlainHistogramWithoutClear() throws Exception {
innerSetUp(false, null, false, false);
Histogram histogram = metricsRegistry.newHistogram(WavefrontYammerMetricsReporterTest.class, "myhisto");
histogram.update(1);
histogram.update(10);
wavefrontYammerMetricsReporter.run();
assertThat(receiveFromSocket(11, fromMetrics), containsInAnyOrder(equalTo("\"myhisto.count\" 2.0 1485224035"), equalTo("\"myhisto.min\" 1.0 1485224035"), equalTo("\"myhisto.max\" 10.0 1485224035"), equalTo("\"myhisto.mean\" 5.5 1485224035"), equalTo("\"myhisto.sum\" 11.0 1485224035"), startsWith("\"myhisto.stddev\""), equalTo("\"myhisto.median\" 5.5 1485224035"), equalTo("\"myhisto.p75\" 10.0 1485224035"), equalTo("\"myhisto.p95\" 10.0 1485224035"), equalTo("\"myhisto.p99\" 10.0 1485224035"), equalTo("\"myhisto.p999\" 10.0 1485224035")));
// Second run should be the same.
wavefrontYammerMetricsReporter.run();
assertThat(receiveFromSocket(11, fromMetrics), containsInAnyOrder(equalTo("\"myhisto.count\" 2.0 1485224035"), equalTo("\"myhisto.min\" 1.0 1485224035"), equalTo("\"myhisto.max\" 10.0 1485224035"), equalTo("\"myhisto.mean\" 5.5 1485224035"), equalTo("\"myhisto.sum\" 11.0 1485224035"), startsWith("\"myhisto.stddev\""), equalTo("\"myhisto.median\" 5.5 1485224035"), equalTo("\"myhisto.p75\" 10.0 1485224035"), equalTo("\"myhisto.p95\" 10.0 1485224035"), equalTo("\"myhisto.p99\" 10.0 1485224035"), equalTo("\"myhisto.p999\" 10.0 1485224035")));
}
use of com.yammer.metrics.core.Histogram in project java by wavefrontHQ.
the class JsonMetricsGeneratorTest method testWavefrontHistogramClear.
@Test
public void testWavefrontHistogramClear() throws IOException {
Histogram wh = WavefrontHistogram.get(testRegistry, new MetricName("test", "", "metric"), time::get);
wh.update(10);
// 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);
generate(false, false, true, null);
wh.update(100);
// 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, true, null);
assertThat(json).isEqualTo("{\"test.metric\":{\"bins\":[{\"count\":1,\"startMillis\":60000,\"durationMillis\":60000,\"means\":[100.0],\"counts\":[1]}]}}");
}
use of com.yammer.metrics.core.Histogram in project java by wavefrontHQ.
the class JsonMetricsGeneratorTest method testWavefrontHistogramSpanMultipleMinutes.
@Test
public void testWavefrontHistogramSpanMultipleMinutes() throws IOException {
Histogram wh = WavefrontHistogram.get(testRegistry, new MetricName("test", "", "metric"), time::get);
wh.update(10);
wh.update(100);
// Simulate the clock advanced by 1 minute
time.set(61 * 1000);
wh.update(1000);
// Simulate the clock advanced by 1 minute
time.set(61 * 1000 * 2);
String json = generate(false, false, false, null);
assertThat(json).isEqualTo("{\"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]}]}}");
}
Aggregations