use of org.apache.hadoop.metrics2.lib.MutableRatesWithAggregation in project hadoop by apache.
the class TestFSNamesystemLock method testDetailedHoldMetrics.
@Test
public void testDetailedHoldMetrics() throws Exception {
Configuration conf = new Configuration();
conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_LOCK_DETAILED_METRICS_KEY, true);
FakeTimer timer = new FakeTimer();
MetricsRegistry registry = new MetricsRegistry("Test");
MutableRatesWithAggregation rates = registry.newRatesWithAggregation("Test");
FSNamesystemLock fsLock = new FSNamesystemLock(conf, rates, timer);
fsLock.readLock();
timer.advance(1);
fsLock.readUnlock("foo");
fsLock.readLock();
timer.advance(2);
fsLock.readUnlock("foo");
fsLock.readLock();
timer.advance(1);
fsLock.readLock();
timer.advance(1);
fsLock.readUnlock("bar");
fsLock.readUnlock("bar");
fsLock.writeLock();
timer.advance(1);
fsLock.writeUnlock("baz");
MetricsRecordBuilder rb = MetricsAsserts.mockMetricsRecordBuilder();
rates.snapshot(rb, true);
assertGauge("FSNReadLockFooAvgTime", 1.5, rb);
assertCounter("FSNReadLockFooNumOps", 2L, rb);
assertGauge("FSNReadLockBarAvgTime", 2.0, rb);
assertCounter("FSNReadLockBarNumOps", 1L, rb);
assertGauge("FSNWriteLockBazAvgTime", 1.0, rb);
assertCounter("FSNWriteLockBazNumOps", 1L, rb);
}
use of org.apache.hadoop.metrics2.lib.MutableRatesWithAggregation in project hadoop by apache.
the class TestMutableMetrics method snapshotMutableRatesWithAggregation.
private static void snapshotMutableRatesWithAggregation(MutableRatesWithAggregation rates, long[] opCount, double[] opTotalTime) {
MetricsRecordBuilder rb = mockMetricsRecordBuilder();
rates.snapshot(rb, true);
for (int i = 0; i < opCount.length; i++) {
long prevOpCount = opCount[i];
long newOpCount = getLongCounter("Metric" + i + "NumOps", rb);
opCount[i] = newOpCount;
double avgTime = getDoubleGauge("Metric" + i + "AvgTime", rb);
opTotalTime[i] += avgTime * (newOpCount - prevOpCount);
}
}
use of org.apache.hadoop.metrics2.lib.MutableRatesWithAggregation in project hadoop by apache.
the class TestMutableMetrics method testMutableRatesWithAggregationInit.
@Test
public void testMutableRatesWithAggregationInit() {
MetricsRecordBuilder rb = mockMetricsRecordBuilder();
MutableRatesWithAggregation rates = new MutableRatesWithAggregation();
rates.init(TestProtocol.class);
rates.snapshot(rb, false);
assertCounter("FooNumOps", 0L, rb);
assertGauge("FooAvgTime", 0.0, rb);
assertCounter("BarNumOps", 0L, rb);
assertGauge("BarAvgTime", 0.0, rb);
}
use of org.apache.hadoop.metrics2.lib.MutableRatesWithAggregation in project hadoop by apache.
the class TestMutableMetrics method testMutableRatesWithAggregationSingleThread.
@Test
public void testMutableRatesWithAggregationSingleThread() {
MutableRatesWithAggregation rates = new MutableRatesWithAggregation();
rates.add("foo", 1);
rates.add("bar", 5);
MetricsRecordBuilder rb = mockMetricsRecordBuilder();
rates.snapshot(rb, false);
assertCounter("FooNumOps", 1L, rb);
assertGauge("FooAvgTime", 1.0, rb);
assertCounter("BarNumOps", 1L, rb);
assertGauge("BarAvgTime", 5.0, rb);
rates.add("foo", 1);
rates.add("foo", 3);
rates.add("bar", 6);
rb = mockMetricsRecordBuilder();
rates.snapshot(rb, false);
assertCounter("FooNumOps", 3L, rb);
assertGauge("FooAvgTime", 2.0, rb);
assertCounter("BarNumOps", 2L, rb);
assertGauge("BarAvgTime", 6.0, rb);
}
Aggregations