Search in sources :

Example 71 with MetricsRecordBuilder

use of org.apache.hadoop.metrics2.MetricsRecordBuilder in project hadoop by apache.

the class TestMetricsAnnotations method testClasses.

@Test
public void testClasses() {
    MetricsRecordBuilder rb = getMetrics(MetricsAnnotations.makeSource(new MyMetrics3()));
    MetricsCollector collector = rb.parent();
    verify(collector).addRecord(info("MyMetrics3", "My metrics"));
    verify(rb).add(tag(MsInfo.Context, "foo"));
}
Also used : MetricsCollector(org.apache.hadoop.metrics2.MetricsCollector) MetricsRecordBuilder(org.apache.hadoop.metrics2.MetricsRecordBuilder) Test(org.junit.Test)

Example 72 with MetricsRecordBuilder

use of org.apache.hadoop.metrics2.MetricsRecordBuilder in project hadoop by apache.

the class TestMetricsRegistry method testAddByName.

/**
   * Test the add by name method
   */
@Test
public void testAddByName() {
    MetricsRecordBuilder rb = mockMetricsRecordBuilder();
    final MetricsRegistry r = new MetricsRegistry("test");
    r.add("s1", 42);
    r.get("s1").snapshot(rb);
    verify(rb).addCounter(info("S1NumOps", "Number of ops for s1"), 1L);
    verify(rb).addGauge(info("S1AvgTime", "Average time for s1"), 42.0);
    r.newCounter("c1", "test add", 1);
    r.newGauge("g1", "test add", 1);
    expectMetricsException("Unsupported add", new Runnable() {

        @Override
        public void run() {
            r.add("c1", 42);
        }
    });
    expectMetricsException("Unsupported add", new Runnable() {

        @Override
        public void run() {
            r.add("g1", 42);
        }
    });
}
Also used : MetricsRecordBuilder(org.apache.hadoop.metrics2.MetricsRecordBuilder) Test(org.junit.Test)

Example 73 with MetricsRecordBuilder

use of org.apache.hadoop.metrics2.MetricsRecordBuilder in project hadoop by apache.

the class TestMutableMetrics method testMutableRates.

@Test
public void testMutableRates() {
    MetricsRecordBuilder rb = mockMetricsRecordBuilder();
    MetricsRegistry registry = new MetricsRegistry("test");
    MutableRates rates = new MutableRates(registry);
    rates.init(TestProtocol.class);
    registry.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 74 with MetricsRecordBuilder

use of org.apache.hadoop.metrics2.MetricsRecordBuilder in project hadoop by apache.

the class TestMutableMetrics method testMutableQuantilesError.

/**
   * Ensure that quantile estimates from {@link MutableQuantiles} are within
   * specified error bounds.
   */
@Test(timeout = 30000)
public void testMutableQuantilesError() throws Exception {
    MetricsRecordBuilder mb = mockMetricsRecordBuilder();
    MetricsRegistry registry = new MetricsRegistry("test");
    // Use a 5s rollover period
    MutableQuantiles quantiles = registry.newQuantiles("foo", "stat", "Ops", "Latency", 5);
    // Push some values in and wait for it to publish
    long start = System.nanoTime() / 1000000;
    for (long i = 1; i <= 1000; i++) {
        quantiles.add(i);
        quantiles.add(1001 - i);
    }
    long end = System.nanoTime() / 1000000;
    Thread.sleep(6000 - (end - start));
    registry.snapshot(mb, false);
    // Print out the snapshot
    Map<Quantile, Long> previousSnapshot = quantiles.previousSnapshot;
    for (Entry<Quantile, Long> item : previousSnapshot.entrySet()) {
        System.out.println(String.format("Quantile %.2f has value %d", item.getKey().quantile, item.getValue()));
    }
    // Verify the results are within our requirements
    verify(mb).addGauge(info("FooNumOps", "Number of ops for stat with 5s interval"), (long) 2000);
    Quantile[] quants = MutableQuantiles.quantiles;
    String name = "Foo%dthPercentileLatency";
    String desc = "%d percentile latency with 5 second interval for stat";
    for (Quantile q : quants) {
        int percentile = (int) (100 * q.quantile);
        int error = (int) (1000 * q.error);
        String n = String.format(name, percentile);
        String d = String.format(desc, percentile);
        long expected = (long) (q.quantile * 1000);
        verify(mb).addGauge(eq(info(n, d)), leq(expected + error));
        verify(mb).addGauge(eq(info(n, d)), geq(expected - error));
    }
}
Also used : Matchers.anyLong(org.mockito.Matchers.anyLong) Quantile(org.apache.hadoop.metrics2.util.Quantile) MetricsRecordBuilder(org.apache.hadoop.metrics2.MetricsRecordBuilder) Test(org.junit.Test)

Example 75 with MetricsRecordBuilder

use of org.apache.hadoop.metrics2.MetricsRecordBuilder in project hadoop by apache.

the class TestMutableMetrics method testMutableStatWithBulkAdd.

/**
   * Tests that when using {@link MutableStat#add(long, long)}, even with a high
   * sample count, the mean does not lose accuracy.
   */
@Test
public void testMutableStatWithBulkAdd() {
    MetricsRecordBuilder rb = mockMetricsRecordBuilder();
    MetricsRegistry registry = new MetricsRegistry("test");
    MutableStat stat = registry.newStat("Test", "Test", "Ops", "Val", false);
    stat.add(1000, 1000);
    stat.add(1000, 2000);
    registry.snapshot(rb, false);
    assertCounter("TestNumOps", 2000L, rb);
    assertGauge("TestAvgVal", 1.5, rb);
}
Also used : MetricsRecordBuilder(org.apache.hadoop.metrics2.MetricsRecordBuilder) Test(org.junit.Test)

Aggregations

MetricsRecordBuilder (org.apache.hadoop.metrics2.MetricsRecordBuilder)99 Test (org.junit.Test)47 Path (org.apache.hadoop.fs.Path)20 Configuration (org.apache.hadoop.conf.Configuration)14 DistributedFileSystem (org.apache.hadoop.hdfs.DistributedFileSystem)12 HdfsConfiguration (org.apache.hadoop.hdfs.HdfsConfiguration)11 MiniDFSCluster (org.apache.hadoop.hdfs.MiniDFSCluster)11 FileSystem (org.apache.hadoop.fs.FileSystem)8 MetricsInfo (org.apache.hadoop.metrics2.MetricsInfo)7 IOException (java.io.IOException)6 MetricsCollector (org.apache.hadoop.metrics2.MetricsCollector)6 MetricsSource (org.apache.hadoop.metrics2.MetricsSource)5 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)4 Quantile (org.apache.hadoop.metrics2.util.Quantile)4 ServiceException (com.google.protobuf.ServiceException)3 InterruptedIOException (java.io.InterruptedIOException)2 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)2 Map (java.util.Map)2 CacheDirectiveInfo (org.apache.hadoop.hdfs.protocol.CacheDirectiveInfo)2 CachePoolInfo (org.apache.hadoop.hdfs.protocol.CachePoolInfo)2