Search in sources :

Example 6 with MutableMetric

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());
}
Also used : MetricsInfo(org.apache.hadoop.metrics2.MetricsInfo) MetricsException(org.apache.hadoop.metrics2.MetricsException)

Aggregations

Annotation (java.lang.annotation.Annotation)3 Metric (org.apache.hadoop.metrics2.annotation.Metric)3 MetricsException (org.apache.hadoop.metrics2.MetricsException)2 MetricsInfo (org.apache.hadoop.metrics2.MetricsInfo)2 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Metrics (org.apache.hadoop.hive.common.metrics.common.Metrics)1 CodahaleMetrics (org.apache.hadoop.hive.common.metrics.metrics2.CodahaleMetrics)1 MetricsRecordBuilder (org.apache.hadoop.metrics2.MetricsRecordBuilder)1 MutableCounterInt (org.apache.hadoop.metrics2.lib.MutableCounterInt)1 MutableGaugeInt (org.apache.hadoop.metrics2.lib.MutableGaugeInt)1 MutableMetric (org.apache.hadoop.metrics2.lib.MutableMetric)1