Search in sources :

Example 21 with Histogram

use of com.codahale.metrics.Histogram in project gerrit by GerritCodeReview.

the class MetricJson method init.

private void init(Metric metric, ImmutableMap<String, String> atts) {
    if (metric instanceof BucketedMetric) {
        BucketedMetric m = (BucketedMetric) metric;
        if (m.getTotal() != null) {
            init(m.getTotal(), atts);
        }
        Field<?>[] fieldList = m.getFields();
        fields = new ArrayList<>(fieldList.length);
        for (Field<?> f : fieldList) {
            fields.add(new FieldJson(f));
        }
        buckets = makeBuckets(fieldList, m.getCells(), atts);
    } else if (metric instanceof Counter) {
        Counter c = (Counter) metric;
        count = c.getCount();
    } else if (metric instanceof Gauge) {
        Gauge<?> g = (Gauge<?>) metric;
        value = g.getValue();
    } else if (metric instanceof Meter) {
        Meter m = (Meter) metric;
        count = m.getCount();
        rate_1m = m.getOneMinuteRate();
        rate_5m = m.getFiveMinuteRate();
        rate_15m = m.getFifteenMinuteRate();
    } else if (metric instanceof Timer) {
        Timer m = (Timer) metric;
        Snapshot s = m.getSnapshot();
        count = m.getCount();
        rate_1m = m.getOneMinuteRate();
        rate_5m = m.getFiveMinuteRate();
        rate_15m = m.getFifteenMinuteRate();
        double div = Description.getTimeUnit(atts.get(Description.UNIT)).toNanos(1);
        p50 = s.getMedian() / div;
        p75 = s.get75thPercentile() / div;
        p95 = s.get95thPercentile() / div;
        p98 = s.get98thPercentile() / div;
        p99 = s.get99thPercentile() / div;
        p99_9 = s.get999thPercentile() / div;
        min = s.getMin() / div;
        max = s.getMax() / div;
        std_dev = s.getStdDev() / div;
    } else if (metric instanceof Histogram) {
        Histogram m = (Histogram) metric;
        Snapshot s = m.getSnapshot();
        count = m.getCount();
        p50 = s.getMedian();
        p75 = s.get75thPercentile();
        p95 = s.get95thPercentile();
        p98 = s.get98thPercentile();
        p99 = s.get99thPercentile();
        p99_9 = s.get999thPercentile();
        min = (double) s.getMin();
        avg = (double) s.getMean();
        max = (double) s.getMax();
        sum = s.getMean() * m.getCount();
        std_dev = s.getStdDev();
    }
}
Also used : Histogram(com.codahale.metrics.Histogram) Meter(com.codahale.metrics.Meter) Gauge(com.codahale.metrics.Gauge) Field(com.google.gerrit.metrics.Field) Snapshot(com.codahale.metrics.Snapshot) Counter(com.codahale.metrics.Counter) Timer(com.codahale.metrics.Timer)

Example 22 with Histogram

use of com.codahale.metrics.Histogram 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 23 with Histogram

use of com.codahale.metrics.Histogram in project ddf by codice.

the class SourceMetricsImplTest method assertMetricCount.

private void assertMetricCount(String sourceId, String metricName, int expectedCount) {
    String key = sourceId + "." + metricName;
    SourceMetric sourceMetric = sourceMetrics.metrics.get(key);
    if (sourceMetric.isHistogram()) {
        Histogram histogram = (Histogram) sourceMetric.getMetric();
        assertThat(histogram.getCount(), is((long) expectedCount));
    } else {
        Meter meter = (Meter) sourceMetric.getMetric();
        assertThat(meter.getCount(), is((long) expectedCount));
    }
}
Also used : Histogram(com.codahale.metrics.Histogram) Meter(com.codahale.metrics.Meter) SourceMetric(ddf.catalog.metrics.source.SourceMetricsImpl.SourceMetric)

Example 24 with Histogram

use of com.codahale.metrics.Histogram in project ddf by codice.

the class SourceMetricsImpl method createMetric.

private void createMetric(String sourceId, String mbeanName, MetricType type) {
    // Create source-specific metrics for this source
    // (Must be done prior to creating metrics collector so that
    // JMX MBean exists for collector to detect).
    String key = sourceId + "." + mbeanName;
    // as the local catalog provider).
    if (!metrics.containsKey(key)) {
        if (type == MetricType.HISTOGRAM) {
            Histogram histogram = metricsRegistry.histogram(MetricRegistry.name(sourceId, mbeanName));
            RrdJmxCollector collector = createGaugeMetricsCollector(sourceId, mbeanName);
            metrics.put(key, new SourceMetric(histogram, collector, true));
        } else if (type == MetricType.METER) {
            Meter meter = metricsRegistry.meter(MetricRegistry.name(sourceId, mbeanName));
            RrdJmxCollector collector = createCounterMetricsCollector(sourceId, mbeanName);
            metrics.put(key, new SourceMetric(meter, collector));
        } else {
            LOGGER.debug("Metric {} not created because unknown metric type {} specified.", key, type);
        }
    } else {
        LOGGER.debug("Metric {} already exists - not creating again", key);
    }
}
Also used : Histogram(com.codahale.metrics.Histogram) Meter(com.codahale.metrics.Meter) RrdJmxCollector(ddf.metrics.collector.rrd4j.RrdJmxCollector)

Example 25 with Histogram

use of com.codahale.metrics.Histogram in project dropwizard by dropwizard.

the class BootstrapTest method bringsYourOwnMetricRegistry.

@Test
public void bringsYourOwnMetricRegistry() {
    final MetricRegistry newRegistry = new MetricRegistry() {

        @Override
        public Histogram histogram(String name) {
            Histogram existed = (Histogram) getMetrics().get(name);
            return existed != null ? existed : new Histogram(new UniformReservoir());
        }
    };
    bootstrap.setMetricRegistry(newRegistry);
    bootstrap.registerMetrics();
    assertThat(newRegistry.getNames()).contains("jvm.buffers.mapped.capacity", "jvm.threads.count", "jvm.memory.heap.usage", "jvm.attribute.vendor", "jvm.classloader.loaded", "jvm.filedescriptor");
}
Also used : Histogram(com.codahale.metrics.Histogram) MetricRegistry(com.codahale.metrics.MetricRegistry) UniformReservoir(com.codahale.metrics.UniformReservoir) Test(org.junit.Test)

Aggregations

Histogram (com.codahale.metrics.Histogram)40 Test (org.junit.Test)18 Timer (com.codahale.metrics.Timer)17 Meter (com.codahale.metrics.Meter)13 Counter (com.codahale.metrics.Counter)11 Snapshot (com.codahale.metrics.Snapshot)8 Gauge (com.codahale.metrics.Gauge)7 MetricRegistry (com.codahale.metrics.MetricRegistry)7 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)5 ZonedDateTime (java.time.ZonedDateTime)5 Map (java.util.Map)5 DateTime (org.joda.time.DateTime)5 Metric (com.codahale.metrics.Metric)4 UniformReservoir (com.codahale.metrics.UniformReservoir)3 SortedMap (java.util.SortedMap)3 AggregateMetric (org.apache.solr.metrics.AggregateMetric)3 MetricSnapshot (backtype.storm.generated.MetricSnapshot)2 JAverageSnapshot (com.alibaba.jstorm.common.metric.codahale.JAverageSnapshot)2 MetricFilter (com.codahale.metrics.MetricFilter)2 Reservoir (com.codahale.metrics.Reservoir)2