Search in sources :

Example 11 with MetricsSource

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

the class TestReadWriteDiskValidator method testCheckFailures.

@Test
public void testCheckFailures() throws Throwable {
    ReadWriteDiskValidator readWriteDiskValidator = (ReadWriteDiskValidator) DiskValidatorFactory.getInstance(ReadWriteDiskValidator.NAME);
    // create a temporary test directory under the system test directory
    File testDir = Files.createTempDirectory(Paths.get(System.getProperty("test.build.data")), "test").toFile();
    try {
        Shell.execCommand(Shell.getSetPermissionCommand("000", false, testDir.getAbsolutePath()));
    } catch (Exception e) {
        testDir.delete();
        throw e;
    }
    try {
        readWriteDiskValidator.checkStatus(testDir);
        fail("Disk check should fail.");
    } catch (DiskErrorException e) {
        assertTrue(e.getMessage().equals("Disk Check failed!"));
    }
    MetricsSource source = ms.getSource(ReadWriteDiskValidatorMetrics.sourceName(testDir.toString()));
    MetricsCollectorImpl collector = new MetricsCollectorImpl();
    source.getMetrics(collector, true);
    try {
        readWriteDiskValidator.checkStatus(testDir);
        fail("Disk check should fail.");
    } catch (DiskErrorException e) {
        assertTrue(e.getMessage().equals("Disk Check failed!"));
    }
    source.getMetrics(collector, true);
    // verify the first metrics record
    MetricsRecords.assertMetric(collector.getRecords().get(0), "FailureCount", 1);
    Long lastFailureTime1 = (Long) MetricsRecords.getMetricValueByName(collector.getRecords().get(0), "LastFailureTime");
    // verify the second metrics record
    MetricsRecords.assertMetric(collector.getRecords().get(1), "FailureCount", 2);
    Long lastFailureTime2 = (Long) MetricsRecords.getMetricValueByName(collector.getRecords().get(1), "LastFailureTime");
    assertTrue("The first failure time should be less than the second one", lastFailureTime1 < lastFailureTime2);
    testDir.delete();
}
Also used : MetricsSource(org.apache.hadoop.metrics2.MetricsSource) DiskErrorException(org.apache.hadoop.util.DiskChecker.DiskErrorException) File(java.io.File) MetricsCollectorImpl(org.apache.hadoop.metrics2.impl.MetricsCollectorImpl) DiskErrorException(org.apache.hadoop.util.DiskChecker.DiskErrorException) Test(org.junit.Test)

Example 12 with MetricsSource

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

the class TestReadWriteDiskValidator method testReadWriteDiskValidator.

@Test
public void testReadWriteDiskValidator() throws DiskErrorException, InterruptedException {
    int count = 100;
    File testDir = new File(System.getProperty("test.build.data"));
    ReadWriteDiskValidator readWriteDiskValidator = (ReadWriteDiskValidator) DiskValidatorFactory.getInstance(ReadWriteDiskValidator.NAME);
    for (int i = 0; i < count; i++) {
        readWriteDiskValidator.checkStatus(testDir);
    }
    ReadWriteDiskValidatorMetrics metric = ReadWriteDiskValidatorMetrics.getMetric(testDir.toString());
    Assert.assertEquals("The count number of estimator in MutableQuantiles" + "metrics of file read is not right", metric.getFileReadQuantiles()[0].getEstimator().getCount(), count);
    Assert.assertEquals("The count number of estimator in MutableQuantiles" + "metrics of file write is not right", metric.getFileWriteQuantiles()[0].getEstimator().getCount(), count);
    MetricsSource source = ms.getSource(ReadWriteDiskValidatorMetrics.sourceName(testDir.toString()));
    MetricsCollectorImpl collector = new MetricsCollectorImpl();
    source.getMetrics(collector, true);
    MetricsRecords.assertMetric(collector.getRecords().get(0), "FailureCount", 0);
    MetricsRecords.assertMetric(collector.getRecords().get(0), "LastFailureTime", (long) 0);
    // All MutableQuantiles haven't rolled over yet because the minimum
    // interval is 1 hours, so we just test if these metrics exist.
    MetricsRecords.assertMetricNotNull(collector.getRecords().get(0), "WriteLatency3600sNumOps");
    MetricsRecords.assertMetricNotNull(collector.getRecords().get(0), "WriteLatency3600s50thPercentileLatencyMicros");
    MetricsRecords.assertMetricNotNull(collector.getRecords().get(0), "WriteLatency86400sNumOps");
    MetricsRecords.assertMetricNotNull(collector.getRecords().get(0), "WriteLatency864000sNumOps");
    MetricsRecords.assertMetricNotNull(collector.getRecords().get(0), "ReadLatency3600sNumOps");
    MetricsRecords.assertMetricNotNull(collector.getRecords().get(0), "ReadLatency3600s50thPercentileLatencyMicros");
    MetricsRecords.assertMetricNotNull(collector.getRecords().get(0), "ReadLatency86400sNumOps");
    MetricsRecords.assertMetricNotNull(collector.getRecords().get(0), "ReadLatency864000sNumOps");
}
Also used : MetricsSource(org.apache.hadoop.metrics2.MetricsSource) File(java.io.File) MetricsCollectorImpl(org.apache.hadoop.metrics2.impl.MetricsCollectorImpl) Test(org.junit.Test)

Example 13 with MetricsSource

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

the class TestMetricsSourceAdapter method testGetMetricsAndJmx.

@Test
public void testGetMetricsAndJmx() throws Exception {
    // create test source with a single metric counter of value 0
    TestSource source = new TestSource("test");
    MetricsSourceBuilder sb = MetricsAnnotations.newSourceBuilder(source);
    final MetricsSource s = sb.build();
    List<MetricsTag> injectedTags = new ArrayList<MetricsTag>();
    MetricsSourceAdapter sa = new MetricsSourceAdapter("test", "test", "test desc", s, injectedTags, null, null, 1, false);
    // all metrics are initially assumed to have changed
    MetricsCollectorImpl builder = new MetricsCollectorImpl();
    Iterable<MetricsRecordImpl> metricsRecords = sa.getMetrics(builder, true);
    // Validate getMetrics and JMX initial values
    MetricsRecordImpl metricsRecord = metricsRecords.iterator().next();
    assertEquals(0L, metricsRecord.metrics().iterator().next().value().longValue());
    // skip JMX cache TTL
    Thread.sleep(100);
    assertEquals(0L, (Number) sa.getAttribute("C1"));
    // change metric value
    source.incrementCnt();
    // validate getMetrics and JMX
    builder = new MetricsCollectorImpl();
    metricsRecords = sa.getMetrics(builder, true);
    metricsRecord = metricsRecords.iterator().next();
    assertTrue(metricsRecord.metrics().iterator().hasNext());
    // skip JMX cache TTL
    Thread.sleep(100);
    assertEquals(1L, (Number) sa.getAttribute("C1"));
}
Also used : MetricsSource(org.apache.hadoop.metrics2.MetricsSource) MetricsSourceBuilder(org.apache.hadoop.metrics2.lib.MetricsSourceBuilder) ArrayList(java.util.ArrayList) MetricsTag(org.apache.hadoop.metrics2.MetricsTag) Test(org.junit.Test)

Example 14 with MetricsSource

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

the class TestMetricsSystemImpl method testUnregisterSource.

@Test
public void testUnregisterSource() {
    MetricsSystem ms = new MetricsSystemImpl();
    TestSource ts1 = new TestSource("ts1");
    TestSource ts2 = new TestSource("ts2");
    ms.register("ts1", "", ts1);
    ms.register("ts2", "", ts2);
    MetricsSource s1 = ms.getSource("ts1");
    assertNotNull(s1);
    // should work when metrics system is not started
    ms.unregisterSource("ts1");
    s1 = ms.getSource("ts1");
    assertNull(s1);
    MetricsSource s2 = ms.getSource("ts2");
    assertNotNull(s2);
    ms.shutdown();
}
Also used : MetricsSource(org.apache.hadoop.metrics2.MetricsSource) DefaultMetricsSystem(org.apache.hadoop.metrics2.lib.DefaultMetricsSystem) MetricsSystem(org.apache.hadoop.metrics2.MetricsSystem) Test(org.junit.Test)

Example 15 with MetricsSource

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

the class TestMetricsAnnotations method testHybrid.

@Test
public void testHybrid() {
    HybridMetrics metrics = new HybridMetrics();
    MetricsSource source = MetricsAnnotations.makeSource(metrics);
    assertSame(metrics, source);
    metrics.C0.incr();
    MetricsRecordBuilder rb = getMetrics(source);
    MetricsCollector collector = rb.parent();
    verify(collector).addRecord("foo");
    verify(collector).addRecord("bar");
    verify(collector).addRecord(info("HybridMetrics", "HybridMetrics"));
    verify(rb).setContext("foocontext");
    verify(rb).addCounter(info("C1", "C1 desc"), 1);
    verify(rb).setContext("barcontext");
    verify(rb).addGauge(info("G1", "G1 desc"), 1);
    verify(rb).add(tag(MsInfo.Context, "hybrid"));
    verify(rb).addCounter(info("C0", "C0 desc"), 1);
    verify(rb).addGauge(info("G0", "G0"), 0);
}
Also used : MetricsCollector(org.apache.hadoop.metrics2.MetricsCollector) MetricsSource(org.apache.hadoop.metrics2.MetricsSource) MetricsRecordBuilder(org.apache.hadoop.metrics2.MetricsRecordBuilder) Test(org.junit.Test)

Aggregations

MetricsSource (org.apache.hadoop.metrics2.MetricsSource)21 Test (org.junit.Test)17 MetricsRecordBuilder (org.apache.hadoop.metrics2.MetricsRecordBuilder)9 MetricsSourceBuilder (org.apache.hadoop.metrics2.lib.MetricsSourceBuilder)4 MetricsSystem (org.apache.hadoop.metrics2.MetricsSystem)3 MetricsCollectorImpl (org.apache.hadoop.metrics2.impl.MetricsCollectorImpl)3 DefaultMetricsSystem (org.apache.hadoop.metrics2.lib.DefaultMetricsSystem)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 MetricsCollector (org.apache.hadoop.metrics2.MetricsCollector)2 MetricsTag (org.apache.hadoop.metrics2.MetricsTag)2 DynamicMetricsRegistry (org.apache.hadoop.metrics2.lib.DynamicMetricsRegistry)2 HashMap (java.util.HashMap)1 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)1 MBeanInfo (javax.management.MBeanInfo)1 Configuration (org.apache.hadoop.conf.Configuration)1 MetricsReplicationGlobalSourceSource (org.apache.hadoop.hbase.replication.regionserver.MetricsReplicationGlobalSourceSource)1 MetricsReplicationGlobalSourceSourceImpl (org.apache.hadoop.hbase.replication.regionserver.MetricsReplicationGlobalSourceSourceImpl)1 MetricsReplicationSourceImpl (org.apache.hadoop.hbase.replication.regionserver.MetricsReplicationSourceImpl)1 MetricsReplicationSourceSource (org.apache.hadoop.hbase.replication.regionserver.MetricsReplicationSourceSource)1