Search in sources :

Example 1 with WavefrontHistogram

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();
}
Also used : Histogram(com.yammer.metrics.core.Histogram) WavefrontHistogram(com.yammer.metrics.core.WavefrontHistogram) WavefrontHistogram(com.yammer.metrics.core.WavefrontHistogram) Map(java.util.Map)

Example 2 with WavefrontHistogram

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);
    }
}
Also used : MetricsRegistry(com.yammer.metrics.core.MetricsRegistry) Histogram(com.yammer.metrics.core.Histogram) WavefrontHistogram(com.yammer.metrics.core.WavefrontHistogram) Counter(com.yammer.metrics.core.Counter) WavefrontHistogram(com.yammer.metrics.core.WavefrontHistogram) TaggedMetricName(com.wavefront.common.TaggedMetricName)

Example 3 with WavefrontHistogram

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();
        }
    }
}
Also used : WavefrontHistogram(com.yammer.metrics.core.WavefrontHistogram)

Example 4 with WavefrontHistogram

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\":[]}}");
}
Also used : MetricName(com.yammer.metrics.core.MetricName) WavefrontHistogram(com.yammer.metrics.core.WavefrontHistogram) Test(org.junit.Test)

Example 5 with WavefrontHistogram

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]}]}}");
}
Also used : MetricName(com.yammer.metrics.core.MetricName) WavefrontHistogram(com.yammer.metrics.core.WavefrontHistogram) Test(org.junit.Test)

Aggregations

WavefrontHistogram (com.yammer.metrics.core.WavefrontHistogram)8 Test (org.junit.Test)5 MetricName (com.yammer.metrics.core.MetricName)4 TaggedMetricName (com.wavefront.common.TaggedMetricName)3 Histogram (com.yammer.metrics.core.Histogram)3 Counter (com.yammer.metrics.core.Counter)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 MetricsRegistry (com.yammer.metrics.core.MetricsRegistry)1 Map (java.util.Map)1