Search in sources :

Example 1 with MutableMetric

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

Example 2 with MutableMetric

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;
}
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)

Example 3 with MutableMetric

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;
    }
}
Also used : Metric(org.apache.hadoop.metrics2.annotation.Metric) Annotation(java.lang.annotation.Annotation)

Example 4 with MutableMetric

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);
            }
        }
    }
}
Also used : Metric(org.apache.hadoop.metrics2.annotation.Metric) MetricsException(org.apache.hadoop.metrics2.MetricsException) Annotation(java.lang.annotation.Annotation) MetricsException(org.apache.hadoop.metrics2.MetricsException)

Example 5 with MutableMetric

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

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