Search in sources :

Example 6 with Snapshot

use of com.codahale.metrics.Snapshot in project indy by Commonjava.

the class IndyZabbixReporter method report.

@SuppressWarnings("rawtypes")
@Override
public void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) {
    final long clock = System.currentTimeMillis() / 1000;
    List<DataObject> dataObjectList = new LinkedList<DataObject>();
    for (Map.Entry<String, Gauge> entry : gauges.entrySet()) {
        DataObject dataObject = toDataObject(entry.getKey(), "", String.valueOf(entry.getValue().getValue()), clock);
        dataObjectList.add(dataObject);
    }
    for (Map.Entry<String, Counter> entry : counters.entrySet()) {
        DataObject dataObject = toDataObject(entry.getKey(), "", String.valueOf(entry.getValue().getCount()), clock);
        dataObjectList.add(dataObject);
    }
    for (Map.Entry<String, Histogram> entry : histograms.entrySet()) {
        Histogram histogram = entry.getValue();
        Snapshot snapshot = histogram.getSnapshot();
        addSnapshotDataObject(entry.getKey(), snapshot, clock, dataObjectList);
    }
    for (Map.Entry<String, Meter> entry : meters.entrySet()) {
        Meter meter = entry.getValue();
        addMeterDataObject(entry.getKey(), meter, clock, dataObjectList);
    }
    for (Map.Entry<String, Timer> entry : timers.entrySet()) {
        Timer timer = entry.getValue();
        addMeterDataObject(entry.getKey(), timer, clock, dataObjectList);
        addSnapshotDataObjectWithConvertDuration(entry.getKey(), timer.getSnapshot(), clock, dataObjectList);
    }
    try {
        SenderResult senderResult = indyZabbixSender.send(dataObjectList, clock);
        if (!senderResult.success()) {
            logger.warn("report metrics to zabbix not success!" + senderResult);
        } else if (logger.isDebugEnabled()) {
            logger.info("report metrics to zabbix success. " + senderResult);
        }
    } catch (IOException e) {
        logger.error("report metrics to zabbix error! " + e);
        e.printStackTrace();
    } catch (IndyMetricsException e) {
        logger.error("Indy metrics config error " + e);
        e.printStackTrace();
    } catch (IndyHttpException e) {
        logger.error("Indy http client error " + e);
        e.printStackTrace();
    }
}
Also used : Histogram(com.codahale.metrics.Histogram) Meter(com.codahale.metrics.Meter) IndyHttpException(org.commonjava.indy.subsys.http.IndyHttpException) IOException(java.io.IOException) LinkedList(java.util.LinkedList) Gauge(com.codahale.metrics.Gauge) Snapshot(com.codahale.metrics.Snapshot) DataObject(org.commonjava.indy.metrics.zabbix.sender.DataObject) Counter(com.codahale.metrics.Counter) Timer(com.codahale.metrics.Timer) Map(java.util.Map) SortedMap(java.util.SortedMap) SenderResult(org.commonjava.indy.metrics.zabbix.sender.SenderResult) IndyMetricsException(org.commonjava.indy.metrics.exception.IndyMetricsException)

Example 7 with Snapshot

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

the class OutputStreamReporter method printTimer.

private void printTimer(Timer timer) {
    final Snapshot snapshot = timer.getSnapshot();
    this.outputBufferPrintStream.printf(locale, "             count = %d%n", timer.getCount());
    this.outputBufferPrintStream.printf(locale, "         mean rate = %2.2f calls/%s%n", convertRate(timer.getMeanRate()), getRateUnit());
    this.outputBufferPrintStream.printf(locale, "     1-minute rate = %2.2f calls/%s%n", convertRate(timer.getOneMinuteRate()), getRateUnit());
    this.outputBufferPrintStream.printf(locale, "     5-minute rate = %2.2f calls/%s%n", convertRate(timer.getFiveMinuteRate()), getRateUnit());
    this.outputBufferPrintStream.printf(locale, "    15-minute rate = %2.2f calls/%s%n", convertRate(timer.getFifteenMinuteRate()), getRateUnit());
    this.outputBufferPrintStream.printf(locale, "               min = %2.2f %s%n", convertDuration(snapshot.getMin()), getDurationUnit());
    this.outputBufferPrintStream.printf(locale, "               max = %2.2f %s%n", convertDuration(snapshot.getMax()), getDurationUnit());
    this.outputBufferPrintStream.printf(locale, "              mean = %2.2f %s%n", convertDuration(snapshot.getMean()), getDurationUnit());
    this.outputBufferPrintStream.printf(locale, "            stddev = %2.2f %s%n", convertDuration(snapshot.getStdDev()), getDurationUnit());
    this.outputBufferPrintStream.printf(locale, "            median = %2.2f %s%n", convertDuration(snapshot.getMedian()), getDurationUnit());
    this.outputBufferPrintStream.printf(locale, "              75%% <= %2.2f %s%n", convertDuration(snapshot.get75thPercentile()), getDurationUnit());
    this.outputBufferPrintStream.printf(locale, "              95%% <= %2.2f %s%n", convertDuration(snapshot.get95thPercentile()), getDurationUnit());
    this.outputBufferPrintStream.printf(locale, "              98%% <= %2.2f %s%n", convertDuration(snapshot.get98thPercentile()), getDurationUnit());
    this.outputBufferPrintStream.printf(locale, "              99%% <= %2.2f %s%n", convertDuration(snapshot.get99thPercentile()), getDurationUnit());
    this.outputBufferPrintStream.printf(locale, "            99.9%% <= %2.2f %s%n", convertDuration(snapshot.get999thPercentile()), getDurationUnit());
}
Also used : Snapshot(com.codahale.metrics.Snapshot)

Example 8 with Snapshot

use of com.codahale.metrics.Snapshot in project bookkeeper by apache.

the class CodahaleOpStatsLogger method toOpStatsData.

/**
 * This function should go away soon (hopefully).
 */
public synchronized OpStatsData toOpStatsData() {
    long numFailed = fail.getCount();
    long numSuccess = success.getCount();
    Snapshot s = success.getSnapshot();
    double avgLatencyMillis = s.getMean();
    double[] defaultPercentiles = { 10, 50, 90, 99, 99.9, 99.99 };
    long[] latenciesMillis = new long[defaultPercentiles.length];
    Arrays.fill(latenciesMillis, Long.MAX_VALUE);
    for (int i = 0; i < defaultPercentiles.length; i++) {
        latenciesMillis[i] = (long) s.getValue(defaultPercentiles[i] / 100);
    }
    return new OpStatsData(numSuccess, numFailed, avgLatencyMillis, latenciesMillis);
}
Also used : Snapshot(com.codahale.metrics.Snapshot)

Example 9 with Snapshot

use of com.codahale.metrics.Snapshot in project infrautils by opendaylight.

the class MetricsFileReporter method printSampling.

private static void printSampling(PrintWriter pw, Sampling sampling) {
    Snapshot snapshot = sampling.getSnapshot();
    printWithSeparator(pw, "min", snapshot.getMin());
    printWithSeparator(pw, "max", snapshot.getMax());
    printWithSeparator(pw, "mean", snapshot.getMean());
}
Also used : Snapshot(com.codahale.metrics.Snapshot)

Example 10 with Snapshot

use of com.codahale.metrics.Snapshot in project stdlib by petergeneric.

the class MetricSerialiser method serialise.

public MetricsHistogram serialise(String name, Histogram histo) {
    Snapshot snapshot = histo.getSnapshot();
    final long count = histo.getCount();
    return new MetricsHistogram(name, count, snapshot.size(), snapshot.getMin(), snapshot.getMax(), snapshot.getStdDev(), snapshot.getMean(), snapshot.getMedian(), snapshot.get75thPercentile(), snapshot.get95thPercentile(), snapshot.get98thPercentile(), snapshot.get99thPercentile(), snapshot.get999thPercentile());
}
Also used : Snapshot(com.codahale.metrics.Snapshot) MetricsHistogram(com.peterphi.std.guice.metrics.rest.types.MetricsHistogram)

Aggregations

Snapshot (com.codahale.metrics.Snapshot)57 Test (org.junit.Test)13 Histogram (com.codahale.metrics.Histogram)11 Timer (com.codahale.metrics.Timer)11 Map (java.util.Map)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 ConcurrentMap (java.util.concurrent.ConcurrentMap)4 HashMap (java.util.HashMap)3 SortedMap (java.util.SortedMap)3 MetricSnapshot (backtype.storm.generated.MetricSnapshot)2 JAverageSnapshot (com.alibaba.jstorm.common.metric.codahale.JAverageSnapshot)2 Counter (com.codahale.metrics.Counter)2 Gauge (com.codahale.metrics.Gauge)2 Meter (com.codahale.metrics.Meter)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 InOrder (org.mockito.InOrder)2 SlidingWindowReservoir (com.codahale.metrics.SlidingWindowReservoir)1 UniformReservoir (com.codahale.metrics.UniformReservoir)1 ResultSet (com.datastax.driver.core.ResultSet)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1