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();
}
}
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);
}
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);
}
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);
}
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;
}
Aggregations