Search in sources :

Example 11 with Histogram

use of com.yammer.metrics.core.Histogram in project Dempsy by Dempsy.

the class TcpTransportTest method testTransportInstantiation.

/**
    * Just send a simple message and make sure it gets through.
    */
@Test
public void testTransportInstantiation() throws Throwable {
    final AtomicBoolean batchedAtLeastOnce = new AtomicBoolean(false);
    runAllCombinations(new Checker() {

        @Override
        public void check(int port, boolean localhost, long batchOutgoingMessagesDelayMillis) throws Throwable {
            final StatsCollector statsCollector = new StatsCollectorFactoryCoda().createStatsCollector(new ClusterId("test", "test-cluster"), new Destination() {
            });
            SenderFactory factory = null;
            TcpReceiver adaptor = null;
            try {
                boolean shouldBatch = batchOutgoingMessagesDelayMillis >= 0;
                if (shouldBatch)
                    batchedAtLeastOnce.set(true);
                TcpTransport transport = new TcpTransport();
                transport.setFailFast(getFailFast());
                // by default batching isn't disabled.
                assertFalse(transport.isBatchingDisabled());
                if (!shouldBatch)
                    transport.setDisableBatching(true);
                if (!shouldBatch)
                    assertTrue(transport.isBatchingDisabled());
                assertEquals(!shouldBatch, transport.isBatchingDisabled());
                //===========================================
                // setup the sender and receiver
                adaptor = (TcpReceiver) transport.createInbound(null);
                adaptor.setStatsCollector(statsCollector);
                StringListener receiver = new StringListener();
                adaptor.setListener(receiver);
                factory = transport.createOutbound(null, statsCollector);
                if (port > 0)
                    adaptor.setPort(port);
                if (localhost)
                    adaptor.setUseLocalhost(localhost);
                //===========================================
                // start the adaptor
                adaptor.start();
                // get the destination
                Destination destination = adaptor.getDestination();
                // send a message
                byte[] messageBytes = "Hello".getBytes();
                Sender sender = factory.getSender(destination);
                assertEquals((shouldBatch ? TcpTransport.defaultBatchingDelayMillis : -1), ((TcpSender) sender).getBatchOutgoingMessagesDelayMillis());
                sender.send(messageBytes);
                sender.send(messageBytes);
                // wait for it to be received.
                for (long endTime = System.currentTimeMillis() + baseTimeoutMillis; endTime > System.currentTimeMillis() && receiver.numMessages.get() < 2; ) Thread.sleep(1);
                assertEquals(2, receiver.numMessages.get());
                // verify everything came over ok.
                assertEquals(1, receiver.receivedStringMessages.size());
                assertEquals("Hello", receiver.receivedStringMessages.iterator().next());
                if (shouldBatch) {
                    // verify the histogram
                    Histogram histogram = ((TcpSender) sender).getBatchingHistogram();
                    assertEquals(calcMean(2), histogram.mean(), 0.0000001);
                    assertEquals(1, histogram.count());
                }
            } finally {
                if (factory != null)
                    factory.stop();
                if (adaptor != null)
                    adaptor.stop();
            }
        }

        @Override
        public String toString() {
            return "testTransportInstantiation";
        }
    });
    assertTrue(batchedAtLeastOnce.get());
}
Also used : Destination(com.nokia.dempsy.messagetransport.Destination) Histogram(com.yammer.metrics.core.Histogram) ClusterId(com.nokia.dempsy.config.ClusterId) StatsCollector(com.nokia.dempsy.monitoring.StatsCollector) BasicStatsCollector(com.nokia.dempsy.monitoring.basic.BasicStatsCollector) Sender(com.nokia.dempsy.messagetransport.Sender) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SenderFactory(com.nokia.dempsy.messagetransport.SenderFactory) StatsCollectorFactoryCoda(com.nokia.dempsy.monitoring.coda.StatsCollectorFactoryCoda) Test(org.junit.Test)

Example 12 with Histogram

use of com.yammer.metrics.core.Histogram in project java by wavefrontHQ.

the class JsonMetricsGeneratorTest method testWavefrontHistogram.

@Test
public void testWavefrontHistogram() throws IOException {
    Histogram wh = WavefrontHistogram.get(testRegistry, new MetricName("test", "", "metric"), time::get);
    wh.update(10);
    wh.update(100);
    wh.update(1000);
    // 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\":3,\"startMillis\":0,\"durationMillis\":60000,\"means\":[10.0,100.0,1000.0],\"counts\":[1,1,1]}]}}");
}
Also used : MetricName(com.yammer.metrics.core.MetricName) Histogram(com.yammer.metrics.core.Histogram) WavefrontHistogram(com.yammer.metrics.core.WavefrontHistogram) Test(org.junit.Test)

Example 13 with Histogram

use of com.yammer.metrics.core.Histogram in project java by wavefrontHQ.

the class JsonMetricsGeneratorTest method testWavefrontHistogramPrunesOldBins.

@Test
public void testWavefrontHistogramPrunesOldBins() throws IOException {
    Histogram wh = WavefrontHistogram.get(testRegistry, new MetricName("test", "", "metric"), time::get);
    // 1
    wh.update(10);
    // 2
    time.set(61 * 1000);
    wh.update(100);
    // 3
    time.set(121 * 1000);
    wh.update(1000);
    // 4
    time.set(181 * 1000);
    wh.update(10000);
    // 5
    time.set(241 * 1000);
    wh.update(100000);
    // 6
    time.set(301 * 1000);
    wh.update(100001);
    // 7
    time.set(361 * 1000);
    wh.update(100011);
    // 8
    time.set(421 * 1000);
    wh.update(100111);
    // 9
    time.set(481 * 1000);
    wh.update(101111);
    // 10
    time.set(541 * 1000);
    wh.update(111111);
    // 11
    time.set(601 * 1000);
    wh.update(111112);
    // 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\":1,\"startMillis\":60000,\"durationMillis\":60000,\"means\":[100.0],\"counts\":[1]},{\"count\":1,\"startMillis\":120000,\"durationMillis\":60000,\"means\":[1000.0],\"counts\":[1]},{\"count\":1,\"startMillis\":180000,\"durationMillis\":60000,\"means\":[10000.0],\"counts\":[1]},{\"count\":1,\"startMillis\":240000,\"durationMillis\":60000,\"means\":[100000.0],\"counts\":[1]},{\"count\":1,\"startMillis\":300000,\"durationMillis\":60000,\"means\":[100001.0],\"counts\":[1]},{\"count\":1,\"startMillis\":360000,\"durationMillis\":60000,\"means\":[100011.0],\"counts\":[1]},{\"count\":1,\"startMillis\":420000,\"durationMillis\":60000,\"means\":[100111.0],\"counts\":[1]},{\"count\":1,\"startMillis\":480000,\"durationMillis\":60000,\"means\":[101111.0],\"counts\":[1]},{\"count\":1,\"startMillis\":540000,\"durationMillis\":60000,\"means\":[111111.0],\"counts\":[1]},{\"count\":1,\"startMillis\":600000,\"durationMillis\":60000,\"means\":[111112.0],\"counts\":[1]}]}}");
}
Also used : MetricName(com.yammer.metrics.core.MetricName) Histogram(com.yammer.metrics.core.Histogram) WavefrontHistogram(com.yammer.metrics.core.WavefrontHistogram) Test(org.junit.Test)

Example 14 with Histogram

use of com.yammer.metrics.core.Histogram in project java by wavefrontHQ.

the class WavefrontYammerMetricsReporterTest method testPrependGroupName.

@Test(timeout = 1000)
public void testPrependGroupName() throws Exception {
    innerSetUp(true, null, false, false);
    // Counter
    TaggedMetricName taggedMetricName = new TaggedMetricName("group", "mycounter", "tag1", "value1", "tag2", "value2");
    Counter counter = metricsRegistry.newCounter(taggedMetricName);
    counter.inc();
    counter.inc();
    AtomicLong clock = new AtomicLong(System.currentTimeMillis());
    // Wavefront Histo
    WavefrontHistogram wavefrontHistogram = WavefrontHistogram.get(metricsRegistry, new TaggedMetricName("group3", "myhisto", "tag1", "value1", "tag2", "value2"), clock::get);
    for (int i = 0; i < 101; i++) {
        wavefrontHistogram.update(i);
    }
    // Exploded Histo
    Histogram histogram = metricsRegistry.newHistogram(new MetricName("group2", "", "myhisto"), false);
    histogram.update(1);
    histogram.update(10);
    // Advance the clock by 1 min ...
    clock.addAndGet(60000L + 1);
    wavefrontYammerMetricsReporter.run();
    assertThat(receiveFromSocket(12, fromMetrics), containsInAnyOrder(equalTo("\"group.mycounter\" 2.0 1485224035 tag1=\"value1\" tag2=\"value2\""), equalTo("\"group2.myhisto.count\" 2.0 1485224035"), equalTo("\"group2.myhisto.min\" 1.0 1485224035"), equalTo("\"group2.myhisto.max\" 10.0 1485224035"), equalTo("\"group2.myhisto.mean\" 5.5 1485224035"), equalTo("\"group2.myhisto.sum\" 11.0 1485224035"), startsWith("\"group2.myhisto.stddev\""), equalTo("\"group2.myhisto.median\" 5.5 1485224035"), equalTo("\"group2.myhisto.p75\" 10.0 1485224035"), equalTo("\"group2.myhisto.p95\" 10.0 1485224035"), equalTo("\"group2.myhisto.p99\" 10.0 1485224035"), equalTo("\"group2.myhisto.p999\" 10.0 1485224035")));
    assertThat(receiveFromSocket(1, fromHistograms), contains(equalTo("!M 1485224035 #101 50.0 \"group3.myhisto\" tag1=\"value1\" tag2=\"value2\"")));
}
Also used : MetricName(com.yammer.metrics.core.MetricName) TaggedMetricName(com.wavefront.common.TaggedMetricName) AtomicLong(java.util.concurrent.atomic.AtomicLong) 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) Test(org.junit.Test)

Example 15 with Histogram

use of com.yammer.metrics.core.Histogram in project java by wavefrontHQ.

the class WavefrontYammerMetricsReporterTest method testPlainHistogramWithClear.

@Test(timeout = 1000)
public void testPlainHistogramWithClear() throws Exception {
    innerSetUp(false, null, false, true);
    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 clear data.
    wavefrontYammerMetricsReporter.run();
    assertThat(receiveFromSocket(11, fromMetrics), hasItem("\"myhisto.count\" 0.0 1485224035"));
}
Also used : Histogram(com.yammer.metrics.core.Histogram) WavefrontHistogram(com.yammer.metrics.core.WavefrontHistogram) Test(org.junit.Test)

Aggregations

Histogram (com.yammer.metrics.core.Histogram)15 WavefrontHistogram (com.yammer.metrics.core.WavefrontHistogram)11 Test (org.junit.Test)10 MetricName (com.yammer.metrics.core.MetricName)7 TaggedMetricName (com.wavefront.common.TaggedMetricName)2 Counter (com.yammer.metrics.core.Counter)2 ArrayList (java.util.ArrayList)2 AggregatedHistogram (com.linkedin.pinot.common.metrics.AggregatedHistogram)1 LatencyMetric (com.linkedin.pinot.common.metrics.LatencyMetric)1 ServerInstance (com.linkedin.pinot.common.response.ServerInstance)1 PerTableRoutingConfig (com.linkedin.pinot.transport.config.PerTableRoutingConfig)1 RoutingTableConfig (com.linkedin.pinot.transport.config.RoutingTableConfig)1 ClusterId (com.nokia.dempsy.config.ClusterId)1 Destination (com.nokia.dempsy.messagetransport.Destination)1 Sender (com.nokia.dempsy.messagetransport.Sender)1 SenderFactory (com.nokia.dempsy.messagetransport.SenderFactory)1 StatsCollector (com.nokia.dempsy.monitoring.StatsCollector)1 BasicStatsCollector (com.nokia.dempsy.monitoring.basic.BasicStatsCollector)1 StatsCollectorFactoryCoda (com.nokia.dempsy.monitoring.coda.StatsCollectorFactoryCoda)1 MetricsRegistry (com.yammer.metrics.core.MetricsRegistry)1