Search in sources :

Example 1 with MutableGaugeInt

use of org.apache.hadoop.metrics2.lib.MutableGaugeInt in project hive by apache.

the class WmPoolMetrics method initAfterRegister.

public void initAfterRegister() {
    // Make sure we capture the same metrics as Hadoop2 metrics system, via annotations.
    if (allMetrics != null)
        return;
    allMetrics = new HashMap<>();
    for (Field field : this.getClass().getDeclaredFields()) {
        for (Annotation annotation : field.getAnnotations()) {
            if (!(annotation instanceof Metric))
                continue;
            try {
                field.setAccessible(true);
                allMetrics.put(field.getName(), (MutableMetric) field.get(this));
            } catch (IllegalAccessException ex) {
                // Not expected, access by the same class.
                break;
            }
            break;
        }
    }
    // Set up codahale if enabled; we cannot tag the values so just prefix them for the JMX view.
    Metrics chMetrics = MetricsFactory.getInstance();
    if (!(chMetrics instanceof CodahaleMetrics))
        return;
    List<String> codahaleNames = new ArrayList<>();
    for (Map.Entry<String, MutableMetric> e : allMetrics.entrySet()) {
        MutableMetric metric = e.getValue();
        MetricsVariable<?> var = null;
        if (metric instanceof MutableCounterInt) {
            var = new CodahaleCounterWrapper((MutableCounterInt) metric);
        } else if (metric instanceof MutableGaugeInt) {
            var = new CodahaleGaugeWrapper((MutableGaugeInt) metric);
        }
        // Unexpected metric type.
        if (var == null)
            continue;
        String name = "WM_" + poolName + "_" + e.getKey();
        codahaleNames.add(name);
        chMetrics.addGauge(name, var);
    }
    this.codahaleGaugeNames = codahaleNames;
}
Also used : MutableCounterInt(org.apache.hadoop.metrics2.lib.MutableCounterInt) ArrayList(java.util.ArrayList) Annotation(java.lang.annotation.Annotation) CodahaleMetrics(org.apache.hadoop.hive.common.metrics.metrics2.CodahaleMetrics) Field(java.lang.reflect.Field) Metrics(org.apache.hadoop.hive.common.metrics.common.Metrics) CodahaleMetrics(org.apache.hadoop.hive.common.metrics.metrics2.CodahaleMetrics) MutableMetric(org.apache.hadoop.metrics2.lib.MutableMetric) MutableGaugeInt(org.apache.hadoop.metrics2.lib.MutableGaugeInt) MutableMetric(org.apache.hadoop.metrics2.lib.MutableMetric) Metric(org.apache.hadoop.metrics2.annotation.Metric) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Annotation (java.lang.annotation.Annotation)1 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 Metric (org.apache.hadoop.metrics2.annotation.Metric)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