Search in sources :

Example 1 with MutableRatesWithAggregation

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);
}
Also used : MutableRatesWithAggregation(org.apache.hadoop.metrics2.lib.MutableRatesWithAggregation) MetricsRegistry(org.apache.hadoop.metrics2.lib.MetricsRegistry) Configuration(org.apache.hadoop.conf.Configuration) FakeTimer(org.apache.hadoop.util.FakeTimer) MetricsRecordBuilder(org.apache.hadoop.metrics2.MetricsRecordBuilder) Test(org.junit.Test)

Example 2 with MutableRatesWithAggregation

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

Example 3 with MutableRatesWithAggregation

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

Example 4 with MutableRatesWithAggregation

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

Aggregations

MetricsRecordBuilder (org.apache.hadoop.metrics2.MetricsRecordBuilder)4 Test (org.junit.Test)3 Configuration (org.apache.hadoop.conf.Configuration)1 MetricsRegistry (org.apache.hadoop.metrics2.lib.MetricsRegistry)1 MutableRatesWithAggregation (org.apache.hadoop.metrics2.lib.MutableRatesWithAggregation)1 FakeTimer (org.apache.hadoop.util.FakeTimer)1