Search in sources :

Example 66 with Histogram

use of com.codahale.metrics.Histogram in project sling by apache.

the class MetricWebConsolePlugin method addHistogramDetails.

private void addHistogramDetails(PrintWriter pw, SortedMap<String, Histogram> histograms) {
    if (histograms.isEmpty()) {
        return;
    }
    pw.println("<br>");
    pw.println("<div class='table'>");
    pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>Histograms</div>");
    pw.println("<table class='nicetable' id='data-histograms'>");
    pw.println("<thead>");
    pw.println("<tr>");
    pw.println("<th class='header'>Name</th>");
    pw.println("<th class='header'>Count</th>");
    pw.println("<th class='header'>50%</th>");
    pw.println("<th class='header'>Min</th>");
    pw.println("<th class='header'>Max</th>");
    pw.println("<th class='header'>Mean</th>");
    pw.println("<th class='header'>StdDev</th>");
    pw.println("<th class='header'>75%</th>");
    pw.println("<th class='header'>95%</th>");
    pw.println("<th class='header'>98%</th>");
    pw.println("<th class='header'>99%</th>");
    pw.println("<th class='header'>999%</th>");
    pw.println("<th>Duration Unit</th>");
    pw.println("</tr>");
    pw.println("</thead>");
    pw.println("<tbody>");
    String rowClass = "odd";
    for (Map.Entry<String, Histogram> e : histograms.entrySet()) {
        Histogram h = e.getValue();
        Snapshot s = h.getSnapshot();
        String name = e.getKey();
        double durationFactor = 1.0 / timeUnit.durationFor(name).toNanos(1);
        String durationUnit = timeUnit.durationFor(name).toString().toLowerCase(Locale.US);
        pw.printf("<tr class='%s ui-state-default'>%n", rowClass);
        pw.printf("<td>%s</td>", name);
        pw.printf("<td>%d</td>", h.getCount());
        pw.printf("<td>%f</td>", s.getMedian() * durationFactor);
        pw.printf("<td>%f</td>", s.getMin() * durationFactor);
        pw.printf("<td>%f</td>", s.getMax() * durationFactor);
        pw.printf("<td>%f</td>", s.getMean() * durationFactor);
        pw.printf("<td>%f</td>", s.getStdDev() * durationFactor);
        pw.printf("<td>%f</td>", s.get75thPercentile() * durationFactor);
        pw.printf("<td>%f</td>", s.get95thPercentile() * durationFactor);
        pw.printf("<td>%f</td>", s.get98thPercentile() * durationFactor);
        pw.printf("<td>%f</td>", s.get99thPercentile() * durationFactor);
        pw.printf("<td>%f</td>", s.get999thPercentile() * durationFactor);
        pw.printf("<td>%s</td>", durationUnit);
        pw.println("</tr>");
        rowClass = "odd".equals(rowClass) ? "even" : "odd";
    }
    pw.println("</tbody>");
    pw.println("</table>");
    pw.println("</div>");
}
Also used : Snapshot(com.codahale.metrics.Snapshot) Histogram(com.codahale.metrics.Histogram) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SortedMap(java.util.SortedMap)

Example 67 with Histogram

use of com.codahale.metrics.Histogram in project sling by apache.

the class MetricWrapperTest method histogram.

@Test
public void histogram() throws Exception {
    Histogram histo = registry.histogram("test");
    HistogramImpl histoStats = new HistogramImpl(histo);
    histoStats.update(100);
    assertEquals(1, histo.getCount());
    assertEquals(1, histoStats.getCount());
    assertEquals(100, histo.getSnapshot().getMax());
    assertSame(histo, histoStats.adaptTo(Histogram.class));
}
Also used : Histogram(com.codahale.metrics.Histogram) Test(org.junit.Test)

Example 68 with Histogram

use of com.codahale.metrics.Histogram in project ambry by linkedin.

the class ReplicationMetrics method populatePerColoMetrics.

/**
 * Updates per colo metrics for each thread pool
 * @param datacenters List of datacenters to replicate from
 */
public void populatePerColoMetrics(Set<String> datacenters) {
    for (String datacenter : datacenters) {
        Meter interColoReplicationBytesRatePerDC = registry.meter(MetricRegistry.name(ReplicaThread.class, "Inter-" + datacenter + "-ReplicationBytesRate"));
        interColoReplicationBytesRate.put(datacenter, interColoReplicationBytesRatePerDC);
        Meter plainTextInterColoReplicationBytesRatePerDC = registry.meter(MetricRegistry.name(ReplicaThread.class, "PlainTextInter-" + datacenter + "-ReplicationBytesRate"));
        plainTextInterColoReplicationBytesRate.put(datacenter, plainTextInterColoReplicationBytesRatePerDC);
        Meter sslInterColoReplicationBytesRatePerDC = registry.meter(MetricRegistry.name(ReplicaThread.class, "SslInter-" + datacenter + "-ReplicationBytesRate"));
        sslInterColoReplicationBytesRate.put(datacenter, sslInterColoReplicationBytesRatePerDC);
        Counter interColoMetadataExchangeCountPerDC = registry.counter(MetricRegistry.name(ReplicaThread.class, "Inter-" + datacenter + "-MetadataExchangeCount"));
        interColoMetadataExchangeCount.put(datacenter, interColoMetadataExchangeCountPerDC);
        Counter interColoReplicationGetRequestCountPerDC = registry.counter(MetricRegistry.name(ReplicaThread.class, "Inter-" + datacenter + "-ReplicationGetRequestCount"));
        interColoReplicationGetRequestCount.put(datacenter, interColoReplicationGetRequestCountPerDC);
        Counter interColoBlobsReplicatedCountPerDC = registry.counter(MetricRegistry.name(ReplicaThread.class, "Inter-" + datacenter + "-ReplicationBlobsCount"));
        interColoBlobsReplicatedCount.put(datacenter, interColoBlobsReplicatedCountPerDC);
        Counter plainTextInterColoMetadataExchangeCountPerDC = registry.counter(MetricRegistry.name(ReplicaThread.class, "PlainTextInter-" + datacenter + "-MetadataExchangeCount"));
        plainTextInterColoMetadataExchangeCount.put(datacenter, plainTextInterColoMetadataExchangeCountPerDC);
        Counter plainTextInterColoBlobsReplicatedCountPerDC = registry.counter(MetricRegistry.name(ReplicaThread.class, "PlainTextInter-" + datacenter + "-BlobsReplicatedCount"));
        plainTextInterColoBlobsReplicatedCount.put(datacenter, plainTextInterColoBlobsReplicatedCountPerDC);
        Counter sslInterColoMetadataExchangeCountPerDC = registry.counter(MetricRegistry.name(ReplicaThread.class, "SslInter-" + datacenter + "-MetadataExchangeCount"));
        sslInterColoMetadataExchangeCount.put(datacenter, sslInterColoMetadataExchangeCountPerDC);
        Counter sslInterColoBlobsReplicatedCountPerDC = registry.counter(MetricRegistry.name(ReplicaThread.class, "SslInter-" + datacenter + "-BlobsReplicatedCount"));
        sslInterColoBlobsReplicatedCount.put(datacenter, sslInterColoBlobsReplicatedCountPerDC);
        Timer interColoReplicationLatencyPerDC = registry.timer(MetricRegistry.name(ReplicaThread.class, "Inter-" + datacenter + "-ReplicationLatency"));
        interColoReplicationLatency.put(datacenter, interColoReplicationLatencyPerDC);
        Timer plainTextInterColoReplicationLatencyPerDC = registry.timer(MetricRegistry.name(ReplicaThread.class, "PlainTextInter-" + datacenter + "-ReplicationLatency"));
        plainTextInterColoReplicationLatency.put(datacenter, plainTextInterColoReplicationLatencyPerDC);
        Timer sslInterColoReplicationLatencyPerDC = registry.timer(MetricRegistry.name(ReplicaThread.class, "SslInter-" + datacenter + "-ReplicationLatency"));
        sslInterColoReplicationLatency.put(datacenter, sslInterColoReplicationLatencyPerDC);
        Histogram interColoExchangeMetadataTimePerDC = registry.histogram(MetricRegistry.name(ReplicaThread.class, "Inter-" + datacenter + "-ExchangeMetadataTime"));
        interColoExchangeMetadataTime.put(datacenter, interColoExchangeMetadataTimePerDC);
        Histogram plainTextInterColoExchangeMetadataTimePerDC = registry.histogram(MetricRegistry.name(ReplicaThread.class, "PlainTextInter-" + datacenter + "-ExchangeMetadataTime"));
        plainTextInterColoExchangeMetadataTime.put(datacenter, plainTextInterColoExchangeMetadataTimePerDC);
        Histogram sslInterColoExchangeMetadataTimePerDC = registry.histogram(MetricRegistry.name(ReplicaThread.class, "SslInter-" + datacenter + "-ExchangeMetadataTime"));
        sslInterColoExchangeMetadataTime.put(datacenter, sslInterColoExchangeMetadataTimePerDC);
        Histogram interColoFixMissingKeysTimePerDC = registry.histogram(MetricRegistry.name(ReplicaThread.class, "Inter-" + datacenter + "-FixMissingKeysTime"));
        interColoFixMissingKeysTime.put(datacenter, interColoFixMissingKeysTimePerDC);
        Histogram plainTextInterColoFixMissingKeysTimePerDC = registry.histogram(MetricRegistry.name(ReplicaThread.class, "PlainTextInter-" + datacenter + "-FixMissingKeysTime"));
        plainTextInterColoFixMissingKeysTime.put(datacenter, plainTextInterColoFixMissingKeysTimePerDC);
        Histogram sslInterColoFixMissingKeysTimePerDC = registry.histogram(MetricRegistry.name(ReplicaThread.class, "SslInter-" + datacenter + "-FixMissingKeysTime"));
        sslInterColoFixMissingKeysTime.put(datacenter, sslInterColoFixMissingKeysTimePerDC);
        Histogram interColoReplicationMetadataRequestTimePerDC = registry.histogram(MetricRegistry.name(ReplicaThread.class, "Inter-" + datacenter + "-ReplicationMetadataRequestTime"));
        interColoReplicationMetadataRequestTime.put(datacenter, interColoReplicationMetadataRequestTimePerDC);
        Histogram plainTextInterColoReplicationMetadataRequestTimePerDC = registry.histogram(MetricRegistry.name(ReplicaThread.class, "PlainTextInter-" + datacenter + "-ReplicationMetadataRequestTime"));
        plainTextInterColoReplicationMetadataRequestTime.put(datacenter, plainTextInterColoReplicationMetadataRequestTimePerDC);
        Histogram sslInterColoReplicationMetadataRequestTimePerDC = registry.histogram(MetricRegistry.name(ReplicaThread.class, "SslInter-" + datacenter + "-ReplicationMetadataRequestTime"));
        sslInterColoReplicationMetadataRequestTime.put(datacenter, sslInterColoReplicationMetadataRequestTimePerDC);
        Histogram interColoCheckMissingKeysTimePerDC = registry.histogram(MetricRegistry.name(ReplicaThread.class, "Inter-" + datacenter + "-CheckMissingKeysTime"));
        interColoCheckMissingKeysTime.put(datacenter, interColoCheckMissingKeysTimePerDC);
        Histogram interColoProcessMetadataResponseTimePerDC = registry.histogram(MetricRegistry.name(ReplicaThread.class, "Inter-" + datacenter + "-ProcessMetadataResponseTime"));
        interColoProcessMetadataResponseTime.put(datacenter, interColoProcessMetadataResponseTimePerDC);
        Histogram interColoGetRequestTimePerDC = registry.histogram(MetricRegistry.name(ReplicaThread.class, "Inter-" + datacenter + "-GetRequestTime"));
        interColoGetRequestTime.put(datacenter, interColoGetRequestTimePerDC);
        Histogram plainTextInterColoGetRequestTimePerDC = registry.histogram(MetricRegistry.name(ReplicaThread.class, "PlainTextInter-" + datacenter + "-GetRequestTime"));
        plainTextInterColoGetRequestTime.put(datacenter, plainTextInterColoGetRequestTimePerDC);
        Histogram sslInterColoGetRequestTimePerDC = registry.histogram(MetricRegistry.name(ReplicaThread.class, "SslInter-" + datacenter + "-GetRequestTime"));
        sslInterColoGetRequestTime.put(datacenter, sslInterColoGetRequestTimePerDC);
        Histogram interColoBatchStoreWriteTimePerDC = registry.histogram(MetricRegistry.name(ReplicaThread.class, "Inter-" + datacenter + "-BatchStoreWriteTime"));
        interColoBatchStoreWriteTime.put(datacenter, interColoBatchStoreWriteTimePerDC);
        Histogram plainTextInterColoBatchStoreWriteTimePerDC = registry.histogram(MetricRegistry.name(ReplicaThread.class, "PlainTextInter-" + datacenter + "-BatchStoreWriteTime"));
        plainTextInterColoBatchStoreWriteTime.put(datacenter, plainTextInterColoBatchStoreWriteTimePerDC);
        Histogram sslInterColoBatchStoreWriteTimePerDC = registry.histogram(MetricRegistry.name(ReplicaThread.class, "SslInter-" + datacenter + "-BatchStoreWriteTime"));
        sslInterColoBatchStoreWriteTime.put(datacenter, sslInterColoBatchStoreWriteTimePerDC);
        Histogram interColoTotalReplicationTimePerDC = registry.histogram(MetricRegistry.name(ReplicaThread.class, "Inter-" + datacenter + "-TotalReplicationTime"));
        interColoTotalReplicationTime.put(datacenter, interColoTotalReplicationTimePerDC);
        Histogram plainTextInterColoTotalReplicationTimePerDC = registry.histogram(MetricRegistry.name(ReplicaThread.class, "PlainTextInter-" + datacenter + "-TotalReplicationTime"));
        plainTextInterColoTotalReplicationTime.put(datacenter, plainTextInterColoTotalReplicationTimePerDC);
        Histogram sslInterColoTotalReplicationTimePerDC = registry.histogram(MetricRegistry.name(ReplicaThread.class, "SslInter-" + datacenter + "-TotalReplicationTime"));
        sslInterColoTotalReplicationTime.put(datacenter, sslInterColoTotalReplicationTimePerDC);
    }
}
Also used : Histogram(com.codahale.metrics.Histogram) Counter(com.codahale.metrics.Counter) Timer(com.codahale.metrics.Timer) Meter(com.codahale.metrics.Meter)

Example 69 with Histogram

use of com.codahale.metrics.Histogram in project opennms by OpenNMS.

the class SyslogReceiverJavaNetImpl method run.

/**
 * The execution context.
 */
@Override
public void run() {
    // Setup logging and create the dispatcher
    super.run();
    // get the context
    m_context = Thread.currentThread();
    // Create some metrics
    Meter packetMeter = METRICS.meter(MetricRegistry.name(getClass(), "packets"));
    Histogram packetSizeHistogram = METRICS.histogram(MetricRegistry.name(getClass(), "packetSize"));
    if (m_stop) {
        LOG.debug("Stop flag set before thread started, exiting");
        return;
    } else {
        LOG.debug("Thread context started");
    }
    // allocate a buffer
    final int length = 0xffff;
    final byte[] buffer = new byte[length];
    try {
        LOG.debug("Creating syslog socket");
        m_dgSock = new DatagramSocket(null);
    } catch (SocketException e) {
        LOG.warn("Could not create syslog socket: " + e.getMessage(), e);
        return;
    }
    // if a socket is closed.
    try {
        LOG.debug("Setting socket timeout to {}ms", SOCKET_TIMEOUT);
        m_dgSock.setSoTimeout(SOCKET_TIMEOUT);
    } catch (SocketException e) {
        LOG.warn("An I/O error occured while trying to set the socket timeout", e);
    }
    // also bound. This shouldn't have any effect at runtime.
    try {
        LOG.debug("Setting socket SO_REUSEADDR to true");
        m_dgSock.setReuseAddress(true);
    } catch (SocketException e) {
        LOG.warn("An I/O error occured while trying to set SO_REUSEADDR", e);
    }
    // Increase the receive buffer for the socket
    try {
        LOG.debug("Attempting to set receive buffer size to {}", Integer.MAX_VALUE);
        m_dgSock.setReceiveBufferSize(Integer.MAX_VALUE);
        LOG.debug("Actual receive buffer size is {}", m_dgSock.getReceiveBufferSize());
    } catch (SocketException e) {
        LOG.info("Failed to set the receive buffer to {}", Integer.MAX_VALUE, e);
    }
    try {
        LOG.debug("Opening datagram socket");
        if (m_config.getListenAddress() != null) {
            m_dgSock.bind(new InetSocketAddress(InetAddressUtils.addr(m_config.getListenAddress()), m_config.getSyslogPort()));
        } else {
            m_dgSock.bind(new InetSocketAddress(m_config.getSyslogPort()));
        }
    } catch (SocketException e) {
        LOG.info("Failed to open datagram socket", e);
    }
    // set to avoid numerous tracing message
    boolean ioInterrupted = false;
    // Construct one mutable {@link DatagramPacket} that will be used for receiving syslog messages
    DatagramPacket pkt = new DatagramPacket(buffer, length);
    // now start processing incoming requests
    while (!m_stop) {
        if (m_context.isInterrupted()) {
            LOG.debug("Thread context interrupted");
            break;
        }
        try {
            if (!ioInterrupted) {
                LOG.debug("Waiting on a datagram to arrive");
            }
            m_dgSock.receive(pkt);
            // Increment the packet counter
            packetMeter.mark();
            // Create a metric for the Syslog packet size
            packetSizeHistogram.update(length);
            final SyslogConnection connection = new SyslogConnection(pkt, true);
            m_dispatcher.send(connection);
            // reset the flag
            ioInterrupted = false;
        } catch (SocketTimeoutException e) {
            ioInterrupted = true;
            continue;
        } catch (InterruptedIOException e) {
            ioInterrupted = true;
            continue;
        } catch (IOException e) {
            if (m_stop) {
                // A SocketException can be thrown during normal shutdown so log as debug
                LOG.debug("Shutting down the datagram receipt port: " + e.getMessage());
            } else {
                LOG.error("An I/O exception occured on the datagram receipt port, exiting", e);
            }
            break;
        }
    }
    // end while status OK
    LOG.debug("Thread context exiting");
}
Also used : SocketException(java.net.SocketException) InterruptedIOException(java.io.InterruptedIOException) Histogram(com.codahale.metrics.Histogram) Meter(com.codahale.metrics.Meter) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException) SocketTimeoutException(java.net.SocketTimeoutException) DatagramSocket(java.net.DatagramSocket) DatagramPacket(java.net.DatagramPacket) SyslogConnection(org.opennms.netmgt.syslogd.api.SyslogConnection)

Example 70 with Histogram

use of com.codahale.metrics.Histogram in project incubator-gobblin by apache.

the class KafkaReporterTest method testKafkaReporter.

@Test
public void testKafkaReporter() throws IOException {
    MetricContext metricContext = MetricContext.builder(this.getClass().getCanonicalName() + ".testKafkaReporter").build();
    Counter counter = metricContext.counter("com.linkedin.example.counter");
    Meter meter = metricContext.meter("com.linkedin.example.meter");
    Histogram histogram = metricContext.histogram("com.linkedin.example.histogram");
    MockKafkaPusher pusher = new MockKafkaPusher();
    KafkaReporter kafkaReporter = getBuilder(pusher).build("localhost:0000", "topic", new Properties());
    counter.inc();
    meter.mark(2);
    histogram.update(1);
    histogram.update(1);
    histogram.update(2);
    kafkaReporter.report(metricContext);
    try {
        Thread.sleep(1000);
    } catch (InterruptedException ex) {
        Thread.currentThread().interrupt();
    }
    Map<String, Double> expected = new HashMap<>();
    expected.put("com.linkedin.example.counter." + Measurements.COUNT, 1.0);
    expected.put("com.linkedin.example.meter." + Measurements.COUNT, 2.0);
    expected.put("com.linkedin.example.histogram." + Measurements.COUNT, 3.0);
    MetricReport nextReport = nextReport(pusher.messageIterator());
    expectMetricsWithValues(nextReport, expected);
    kafkaReporter.report(metricContext);
    try {
        Thread.sleep(1000);
    } catch (InterruptedException ex) {
        Thread.currentThread().interrupt();
    }
    Set<String> expectedSet = new HashSet<>();
    expectedSet.add("com.linkedin.example.counter." + Measurements.COUNT);
    expectedSet.add("com.linkedin.example.meter." + Measurements.COUNT);
    expectedSet.add("com.linkedin.example.meter." + Measurements.MEAN_RATE);
    expectedSet.add("com.linkedin.example.meter." + Measurements.RATE_1MIN);
    expectedSet.add("com.linkedin.example.meter." + Measurements.RATE_5MIN);
    expectedSet.add("com.linkedin.example.meter." + Measurements.RATE_15MIN);
    expectedSet.add("com.linkedin.example.histogram." + Measurements.MEAN);
    expectedSet.add("com.linkedin.example.histogram." + Measurements.MIN);
    expectedSet.add("com.linkedin.example.histogram." + Measurements.MAX);
    expectedSet.add("com.linkedin.example.histogram." + Measurements.MEDIAN);
    expectedSet.add("com.linkedin.example.histogram." + Measurements.PERCENTILE_75TH);
    expectedSet.add("com.linkedin.example.histogram." + Measurements.PERCENTILE_95TH);
    expectedSet.add("com.linkedin.example.histogram." + Measurements.PERCENTILE_99TH);
    expectedSet.add("com.linkedin.example.histogram." + Measurements.PERCENTILE_999TH);
    expectedSet.add("com.linkedin.example.histogram." + Measurements.COUNT);
    nextReport = nextReport(pusher.messageIterator());
    expectMetrics(nextReport, expectedSet, true);
    kafkaReporter.close();
}
Also used : Histogram(com.codahale.metrics.Histogram) Meter(com.codahale.metrics.Meter) HashMap(java.util.HashMap) Properties(java.util.Properties) Counter(com.codahale.metrics.Counter) MetricContext(org.apache.gobblin.metrics.MetricContext) MetricReport(org.apache.gobblin.metrics.MetricReport) KafkaReporter(org.apache.gobblin.metrics.kafka.KafkaReporter) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

Histogram (com.codahale.metrics.Histogram)97 Test (org.junit.Test)39 Timer (com.codahale.metrics.Timer)34 Counter (com.codahale.metrics.Counter)30 Meter (com.codahale.metrics.Meter)29 Gauge (com.codahale.metrics.Gauge)17 Snapshot (com.codahale.metrics.Snapshot)12 Map (java.util.Map)11 Test (org.testng.annotations.Test)11 MetricRegistry (com.codahale.metrics.MetricRegistry)9 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)8 IOException (java.io.IOException)8 HashMap (java.util.HashMap)8 Metric (com.codahale.metrics.Metric)6 Reservoir (com.codahale.metrics.Reservoir)6 ZonedDateTime (java.time.ZonedDateTime)6 Properties (java.util.Properties)6 SortedMap (java.util.SortedMap)6 DateTime (org.joda.time.DateTime)6 UniformReservoir (com.codahale.metrics.UniformReservoir)5