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;
}
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;
}
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();
}
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).");
}
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();
}
Aggregations