use of org.apache.hadoop.metrics2.lib.MutableCounterInt 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;
}
Aggregations