use of org.apache.hadoop.metrics2.lib.MutableMetric in project accumulo by apache.
the class Metrics2TabletServerMetrics method getMetrics.
@Override
public void getMetrics(MetricsCollector collector, boolean all) {
MetricsRecordBuilder builder = collector.addRecord(RECORD).setContext(CONTEXT);
// Update each MutableMetric with the new value
snapshot();
// Add then all to the builder
registry.snapshot(builder, all);
// TODO Some day, MetricsRegistry will also support the MetricsGaugeDouble or allow us to instantiate it directly
builder.addGauge(Interns.info(FILES_PER_TABLET, "Number of files per tablet"), util.getAverageFilesPerTablet());
builder.addGauge(Interns.info(HOLD_TIME, "Time commits held"), util.getHoldTime());
builder.addGauge(Interns.info(INGEST_RATE, "Ingest rate (entries/sec)"), util.getIngest());
builder.addGauge(Interns.info(INGEST_BYTE_RATE, "Ingest rate (bytes/sec)"), util.getIngestByteRate());
builder.addGauge(Interns.info(QUERY_RATE, "Query rate (entries/sec)"), util.getQueryRate());
builder.addGauge(Interns.info(QUERY_BYTE_RATE, "Query rate (bytes/sec)"), util.getQueryByteRate());
builder.addGauge(Interns.info(SCANNED_RATE, "Scanned rate"), util.getScannedRate());
}
use of org.apache.hadoop.metrics2.lib.MutableMetric 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;
}
use of org.apache.hadoop.metrics2.lib.MutableMetric in project hadoop by apache.
the class MetricsSourceBuilder method add.
/** Add {@link MutableMetric} for a method annotated with {@link Metric} */
private void add(Object source, Method method) {
for (Annotation annotation : method.getAnnotations()) {
if (!(annotation instanceof Metric)) {
continue;
}
factory.newForMethod(source, method, (Metric) annotation, registry);
hasAtMetric = true;
}
}
use of org.apache.hadoop.metrics2.lib.MutableMetric in project hadoop by apache.
the class MetricsSourceBuilder method add.
/**
* Change the declared field {@code field} in {@code source} Object to
* {@link MutableMetric}
*/
private void add(Object source, Field field) {
for (Annotation annotation : field.getAnnotations()) {
if (!(annotation instanceof Metric)) {
continue;
}
try {
// skip fields already set
field.setAccessible(true);
if (field.get(source) != null)
continue;
} catch (Exception e) {
LOG.warn("Error accessing field " + field + " annotated with" + annotation, e);
continue;
}
MutableMetric mutable = factory.newForField(field, (Metric) annotation, registry);
if (mutable != null) {
try {
// Set the source field to MutableMetric
field.set(source, mutable);
hasAtMetric = true;
} catch (Exception e) {
throw new MetricsException("Error setting field " + field + " annotated with " + annotation, e);
}
}
}
}
use of org.apache.hadoop.metrics2.lib.MutableMetric in project hadoop by apache.
the class MutableMetricsFactory method newForMethod.
MutableMetric newForMethod(Object source, Method method, Metric annotation, MetricsRegistry registry) {
if (LOG.isDebugEnabled()) {
LOG.debug("method " + method + " with annotation " + annotation);
}
MetricsInfo info = getInfo(annotation, method);
MutableMetric metric = newForMethod(source, method, annotation);
metric = metric != null ? metric : new MethodMetric(source, method, info, annotation.type());
registry.add(info.name(), metric);
return metric;
}
Aggregations