Search in sources :

Example 26 with Counter

use of com.codahale.metrics.Counter 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 27 with Counter

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

the class ProcMetricModuleTest method counter1.

@Test
public void counter1() {
    Counter1<String> cntr = metrics.newCounter("test/count", new Description("simple test").setCumulative(), Field.ofString("action"));
    Counter total = get("test/count_total", Counter.class);
    assertThat(total.getCount()).isEqualTo(0);
    cntr.increment("passed");
    Counter passed = get("test/count/passed", Counter.class);
    assertThat(total.getCount()).isEqualTo(1);
    assertThat(passed.getCount()).isEqualTo(1);
    cntr.incrementBy("failed", 5);
    Counter failed = get("test/count/failed", Counter.class);
    assertThat(total.getCount()).isEqualTo(6);
    assertThat(passed.getCount()).isEqualTo(1);
    assertThat(failed.getCount()).isEqualTo(5);
}
Also used : Description(com.google.gerrit.metrics.Description) Counter(com.codahale.metrics.Counter) Test(org.junit.Test)

Example 28 with Counter

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

the class ProcMetricModuleTest method counter0.

@Test
public void counter0() {
    Counter0 cntr = metrics.newCounter("test/count", new Description("simple test").setCumulative());
    Counter raw = get("test/count", Counter.class);
    assertThat(raw.getCount()).isEqualTo(0);
    cntr.increment();
    assertThat(raw.getCount()).isEqualTo(1);
    cntr.incrementBy(5);
    assertThat(raw.getCount()).isEqualTo(6);
}
Also used : Description(com.google.gerrit.metrics.Description) Counter(com.codahale.metrics.Counter) Counter0(com.google.gerrit.metrics.Counter0) Test(org.junit.Test)

Example 29 with Counter

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

the class ProcMetricModuleTest method counterPrefixFields.

@Test
public void counterPrefixFields() {
    Counter1<String> cntr = metrics.newCounter("test/count", new Description("simple test").setCumulative().setFieldOrdering(FieldOrdering.PREFIX_FIELDS_BASENAME), Field.ofString("action"));
    Counter total = get("test/count_total", Counter.class);
    assertThat(total.getCount()).isEqualTo(0);
    cntr.increment("passed");
    Counter passed = get("test/passed/count", Counter.class);
    assertThat(total.getCount()).isEqualTo(1);
    assertThat(passed.getCount()).isEqualTo(1);
    cntr.incrementBy("failed", 5);
    Counter failed = get("test/failed/count", Counter.class);
    assertThat(total.getCount()).isEqualTo(6);
    assertThat(passed.getCount()).isEqualTo(1);
    assertThat(failed.getCount()).isEqualTo(5);
}
Also used : Description(com.google.gerrit.metrics.Description) Counter(com.codahale.metrics.Counter) Test(org.junit.Test)

Example 30 with Counter

use of com.codahale.metrics.Counter in project oxCore by GluuFederation.

the class LdapEntryReporter method builCounterEntries.

private List<MetricEntry> builCounterEntries(SortedMap<String, Counter> counters, Set<MetricType> registeredMetricTypes) {
    List<MetricEntry> result = new ArrayList<MetricEntry>();
    Set<MetricType> currentRegisteredMetricTypes = new HashSet<MetricType>(registeredMetricTypes);
    for (MetricType metricType : currentRegisteredMetricTypes) {
        Counter counter = counters.get(metricType.getValue());
        if (counter != null) {
            long count = counter.getCount();
            // Remove to avoid writing not changed statistic
            // registeredMetricTypes.remove(metricType);
            CounterMetricData counterMetricData = new CounterMetricData(count);
            CounterMetricEntry counterMetricEntry = new CounterMetricEntry();
            counterMetricEntry.setMetricData(counterMetricData);
            counterMetricEntry.setMetricType(metricType);
            result.add(counterMetricEntry);
        }
    }
    return result;
}
Also used : Counter(com.codahale.metrics.Counter) MetricType(org.xdi.model.metric.MetricType) ArrayList(java.util.ArrayList) CounterMetricEntry(org.xdi.model.metric.counter.CounterMetricEntry) TimerMetricEntry(org.xdi.model.metric.timer.TimerMetricEntry) MetricEntry(org.xdi.model.metric.ldap.MetricEntry) CounterMetricEntry(org.xdi.model.metric.counter.CounterMetricEntry) CounterMetricData(org.xdi.model.metric.counter.CounterMetricData) HashSet(java.util.HashSet)

Aggregations

Counter (com.codahale.metrics.Counter)55 Test (org.junit.Test)24 Map (java.util.Map)15 Timer (com.codahale.metrics.Timer)14 MetricRegistry (com.codahale.metrics.MetricRegistry)13 HashMap (java.util.HashMap)11 Gauge (com.codahale.metrics.Gauge)10 Histogram (com.codahale.metrics.Histogram)10 Metric (com.codahale.metrics.Metric)9 Meter (com.codahale.metrics.Meter)8 Random (java.util.Random)8 SolrInfoBean (org.apache.solr.core.SolrInfoBean)6 SortedMap (java.util.SortedMap)5 IOException (java.io.IOException)4 TreeMap (java.util.TreeMap)4 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)4 SolrMetricManager (org.apache.solr.metrics.SolrMetricManager)4 Description (com.google.gerrit.metrics.Description)3 ArrayList (java.util.ArrayList)3 Collectors (java.util.stream.Collectors)3