use of org.apache.hadoop.metrics2.lib.MutableMetric in project hadoop by apache.
the class MutableMetricsFactory method newForField.
MutableMetric newForField(Field field, Metric annotation, MetricsRegistry registry) {
if (LOG.isDebugEnabled()) {
LOG.debug("field " + field + " with annotation " + annotation);
}
MetricsInfo info = getInfo(annotation, field);
MutableMetric metric = newForField(field, annotation);
if (metric != null) {
registry.add(info.name(), metric);
return metric;
}
final Class<?> cls = field.getType();
if (cls == MutableCounterInt.class) {
return registry.newCounter(info, 0);
}
if (cls == MutableCounterLong.class) {
return registry.newCounter(info, 0L);
}
if (cls == MutableGaugeInt.class) {
return registry.newGauge(info, 0);
}
if (cls == MutableGaugeLong.class) {
return registry.newGauge(info, 0L);
}
if (cls == MutableRate.class) {
return registry.newRate(info.name(), info.description(), annotation.always());
}
if (cls == MutableRates.class) {
return new MutableRates(registry);
}
if (cls == MutableRatesWithAggregation.class) {
return registry.newRatesWithAggregation(info.name());
}
if (cls == MutableStat.class) {
return registry.newStat(info.name(), info.description(), annotation.sampleName(), annotation.valueName(), annotation.always());
}
throw new MetricsException("Unsupported metric field " + field.getName() + " of type " + field.getType().getName());
}
Aggregations