Search in sources :

Example 1 with Metrics

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

the class ReadWriteDiskValidatorMetrics method getMetric.

/**
   * Get a metric by given directory name.
   *
   * @param dirName directory name
   * @return the metric
   */
public static synchronized ReadWriteDiskValidatorMetrics getMetric(String dirName) {
    MetricsSystem ms = DefaultMetricsSystem.instance();
    ReadWriteDiskValidatorMetrics metrics = DIR_METRICS.get(dirName);
    if (metrics == null) {
        metrics = new ReadWriteDiskValidatorMetrics();
        // Register with the MetricsSystems
        if (ms != null) {
            metrics = ms.register(sourceName(dirName), "Metrics for directory: " + dirName, metrics);
        }
        DIR_METRICS.put(dirName, metrics);
    }
    return metrics;
}
Also used : MetricsSystem(org.apache.hadoop.metrics2.MetricsSystem)

Example 2 with Metrics

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

the class MetricsSourceAdapter method updateAttrCache.

private int updateAttrCache(Iterable<MetricsRecordImpl> lastRecs) {
    Preconditions.checkNotNull(lastRecs, "LastRecs should not be null");
    LOG.debug("Updating attr cache...");
    int recNo = 0;
    int numMetrics = 0;
    for (MetricsRecordImpl record : lastRecs) {
        for (MetricsTag t : record.tags()) {
            setAttrCacheTag(t, recNo);
            ++numMetrics;
        }
        for (AbstractMetric m : record.metrics()) {
            setAttrCacheMetric(m, recNo);
            ++numMetrics;
        }
        ++recNo;
    }
    LOG.debug("Done. # tags & metrics=" + numMetrics);
    return numMetrics;
}
Also used : AbstractMetric(org.apache.hadoop.metrics2.AbstractMetric) MetricsTag(org.apache.hadoop.metrics2.MetricsTag)

Example 3 with Metrics

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

the class MetricsSystemImpl method start.

@Override
public synchronized void start() {
    checkNotNull(prefix, "prefix");
    if (monitoring) {
        LOG.warn(prefix + " metrics system already started!", new MetricsException("Illegal start"));
        return;
    }
    for (Callback cb : callbacks) cb.preStart();
    for (Callback cb : namedCallbacks.values()) cb.preStart();
    configure(prefix);
    startTimer();
    monitoring = true;
    LOG.info(prefix + " metrics system started");
    for (Callback cb : callbacks) cb.postStart();
    for (Callback cb : namedCallbacks.values()) cb.postStart();
}
Also used : MetricsException(org.apache.hadoop.metrics2.MetricsException)

Example 4 with Metrics

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

the class MetricsSystemImpl method startTimer.

private synchronized void startTimer() {
    if (timer != null) {
        LOG.warn(prefix + " metrics system timer already started!");
        return;
    }
    logicalTime = 0;
    long millis = period;
    timer = new Timer("Timer for '" + prefix + "' metrics system", true);
    timer.scheduleAtFixedRate(new TimerTask() {

        @Override
        public void run() {
            try {
                onTimerEvent();
            } catch (Exception e) {
                LOG.warn("Error invoking metrics timer", e);
            }
        }
    }, millis, millis);
    LOG.info("Scheduled Metric snapshot period at " + (period / 1000) + " second(s).");
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask) MetricsException(org.apache.hadoop.metrics2.MetricsException)

Example 5 with Metrics

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

the class MetricsSystemImpl method stop.

@Override
public synchronized void stop() {
    if (!monitoring && !DefaultMetricsSystem.inMiniClusterMode()) {
        LOG.warn(prefix + " metrics system not yet started!", new MetricsException("Illegal stop"));
        return;
    }
    if (!monitoring) {
        // in mini cluster mode
        LOG.info(prefix + " metrics system stopped (again)");
        return;
    }
    for (Callback cb : callbacks) cb.preStop();
    for (Callback cb : namedCallbacks.values()) cb.preStop();
    LOG.info("Stopping " + prefix + " metrics system...");
    stopTimer();
    stopSources();
    stopSinks();
    clearConfigs();
    monitoring = false;
    LOG.info(prefix + " metrics system stopped.");
    for (Callback cb : callbacks) cb.postStop();
    for (Callback cb : namedCallbacks.values()) cb.postStop();
}
Also used : MetricsException(org.apache.hadoop.metrics2.MetricsException)

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