Search in sources :

Example 66 with Metrics

use of org.apache.hadoop.metrics2.annotation.Metrics in project hadoop by apache.

the class SharedCacheUploaderMetrics method create.

static SharedCacheUploaderMetrics create() {
    MetricsSystem ms = DefaultMetricsSystem.instance();
    SharedCacheUploaderMetrics metrics = new SharedCacheUploaderMetrics();
    ms.register("SharedCacheUploaderRequests", null, metrics);
    return metrics;
}
Also used : MetricsSystem(org.apache.hadoop.metrics2.MetricsSystem) DefaultMetricsSystem(org.apache.hadoop.metrics2.lib.DefaultMetricsSystem)

Example 67 with Metrics

use of org.apache.hadoop.metrics2.annotation.Metrics in project hbase by apache.

the class Interns method tag.

/**
   * Get a metrics tag
   *
   * @param info  of the tag
   * @param value of the tag
   * @return an interned metrics tag
   */
public static MetricsTag tag(MetricsInfo info, String value) {
    Map<String, MetricsTag> map = tagCache.getUnchecked(info);
    MetricsTag tag = map.get(value);
    if (tag == null) {
        tag = new MetricsTag(info, value);
        map.put(value, tag);
    }
    return tag;
}
Also used : MetricsTag(org.apache.hadoop.metrics2.MetricsTag)

Example 68 with Metrics

use of org.apache.hadoop.metrics2.annotation.Metrics in project hbase by apache.

the class HBaseMetrics2HadoopMetricsAdapter method snapshotAllMetrics.

/**
   * Iterates over the MetricRegistry and adds them to the {@code collector}.
   *
   * @param collector A metrics collector
   */
public void snapshotAllMetrics(MetricRegistry metricRegistry, MetricsCollector collector) {
    MetricRegistryInfo info = metricRegistry.getMetricRegistryInfo();
    MetricsRecordBuilder builder = collector.addRecord(Interns.info(info.getMetricsName(), info.getMetricsDescription()));
    builder.setContext(info.getMetricsContext());
    snapshotAllMetrics(metricRegistry, builder);
}
Also used : MetricRegistryInfo(org.apache.hadoop.hbase.metrics.MetricRegistryInfo) MetricsRecordBuilder(org.apache.hadoop.metrics2.MetricsRecordBuilder)

Example 69 with Metrics

use of org.apache.hadoop.metrics2.annotation.Metrics in project hbase by apache.

the class HBaseMetrics2HadoopMetricsAdapter method snapshotAllMetrics.

/**
   * Iterates over the MetricRegistry and adds them to the {@code builder}.
   *
   * @param builder A record builder
   */
public void snapshotAllMetrics(MetricRegistry metricRegistry, MetricsRecordBuilder builder) {
    Map<String, Metric> metrics = metricRegistry.getMetrics();
    for (Map.Entry<String, Metric> e : metrics.entrySet()) {
        // Always capitalize the name
        String name = StringUtils.capitalize(e.getKey());
        Metric metric = e.getValue();
        if (metric instanceof Gauge) {
            addGauge(name, (Gauge<?>) metric, builder);
        } else if (metric instanceof Counter) {
            addCounter(name, (Counter) metric, builder);
        } else if (metric instanceof Histogram) {
            addHistogram(name, (Histogram) metric, builder);
        } else if (metric instanceof Meter) {
            addMeter(name, (Meter) metric, builder);
        } else if (metric instanceof Timer) {
            addTimer(name, (Timer) metric, builder);
        } else {
            LOG.info("Ignoring unknown Metric class " + metric.getClass().getName());
        }
    }
}
Also used : MutableHistogram(org.apache.hadoop.metrics2.lib.MutableHistogram) Histogram(org.apache.hadoop.hbase.metrics.Histogram) Counter(org.apache.hadoop.hbase.metrics.Counter) Timer(org.apache.hadoop.hbase.metrics.Timer) Meter(org.apache.hadoop.hbase.metrics.Meter) Metric(org.apache.hadoop.hbase.metrics.Metric) Map(java.util.Map) Gauge(org.apache.hadoop.hbase.metrics.Gauge)

Example 70 with Metrics

use of org.apache.hadoop.metrics2.annotation.Metrics in project hbase by apache.

the class MetricsTableAggregateSourceImpl method getMetrics.

/**
   * Yes this is a get function that doesn't return anything.  Thanks Hadoop for breaking all
   * expectations of java programmers.  Instead of returning anything Hadoop metrics expects
   * getMetrics to push the metrics into the collector.
   *
   * @param collector the collector
   * @param all       get all the metrics regardless of when they last changed.
   */
@Override
public void getMetrics(MetricsCollector collector, boolean all) {
    MetricsRecordBuilder mrb = collector.addRecord(metricsName);
    if (tableSources != null) {
        for (MetricsTableSource tableMetricSource : tableSources.values()) {
            if (tableMetricSource instanceof MetricsTableSourceImpl) {
                ((MetricsTableSourceImpl) tableMetricSource).snapshot(mrb, all);
            }
        }
        mrb.addGauge(Interns.info(NUM_TABLES, NUMBER_OF_TABLES_DESC), tableSources.size());
        metricsRegistry.snapshot(mrb, all);
    }
}
Also used : MetricsRecordBuilder(org.apache.hadoop.metrics2.MetricsRecordBuilder)

Aggregations

Test (org.junit.Test)67 MetricsRecordBuilder (org.apache.hadoop.metrics2.MetricsRecordBuilder)30 MetricsRecord (org.apache.hadoop.metrics2.MetricsRecord)20 AbstractMetric (org.apache.hadoop.metrics2.AbstractMetric)19 MetricsSystem (org.apache.hadoop.metrics2.MetricsSystem)19 MetricsTag (org.apache.hadoop.metrics2.MetricsTag)18 MetricsSource (org.apache.hadoop.metrics2.MetricsSource)16 ArrayList (java.util.ArrayList)11 IOException (java.io.IOException)10 HashSet (java.util.HashSet)8 Path (org.apache.hadoop.fs.Path)8 MetricsException (org.apache.hadoop.metrics2.MetricsException)8 MetricsCollectorImpl (org.apache.hadoop.metrics2.impl.MetricsCollectorImpl)7 DefaultMetricsSystem (org.apache.hadoop.metrics2.lib.DefaultMetricsSystem)7 Configuration (org.apache.hadoop.conf.Configuration)5 Map (java.util.Map)4 FileSystem (org.apache.hadoop.fs.FileSystem)4 MetricsSink (org.apache.hadoop.metrics2.MetricsSink)4 MetricsSystemImpl (org.apache.hadoop.metrics2.impl.MetricsSystemImpl)4 GraphiteSink (org.apache.hadoop.metrics2.sink.GraphiteSink)4