Search in sources :

Example 26 with MetricsRecordBuilder

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

the class TestStartupProgressMetrics method testInitialState.

@Test
public void testInitialState() {
    MetricsRecordBuilder builder = getMetrics(metrics, true);
    assertCounter("ElapsedTime", 0L, builder);
    assertGauge("PercentComplete", 0.0f, builder);
    assertCounter("LoadingFsImageCount", 0L, builder);
    assertCounter("LoadingFsImageElapsedTime", 0L, builder);
    assertCounter("LoadingFsImageTotal", 0L, builder);
    assertGauge("LoadingFsImagePercentComplete", 0.0f, builder);
    assertCounter("LoadingEditsCount", 0L, builder);
    assertCounter("LoadingEditsElapsedTime", 0L, builder);
    assertCounter("LoadingEditsTotal", 0L, builder);
    assertGauge("LoadingEditsPercentComplete", 0.0f, builder);
    assertCounter("SavingCheckpointCount", 0L, builder);
    assertCounter("SavingCheckpointElapsedTime", 0L, builder);
    assertCounter("SavingCheckpointTotal", 0L, builder);
    assertGauge("SavingCheckpointPercentComplete", 0.0f, builder);
    assertCounter("SafeModeCount", 0L, builder);
    assertCounter("SafeModeElapsedTime", 0L, builder);
    assertCounter("SafeModeTotal", 0L, builder);
    assertGauge("SafeModePercentComplete", 0.0f, builder);
}
Also used : MetricsRecordBuilder(org.apache.hadoop.metrics2.MetricsRecordBuilder) Test(org.junit.Test)

Example 27 with MetricsRecordBuilder

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

the class StartupProgressMetrics method addCounter.

/**
   * Adds a counter with a name built by using the specified phase's name as
   * prefix and then appending the specified suffix.
   * 
   * @param builder MetricsRecordBuilder to receive counter
   * @param phase Phase to add
   * @param nameSuffix String suffix of metric name
   * @param descSuffix String suffix of metric description
   * @param value long counter value
   */
private static void addCounter(MetricsRecordBuilder builder, Phase phase, String nameSuffix, String descSuffix, long value) {
    MetricsInfo metricsInfo = info(phase.getName() + nameSuffix, phase.getDescription() + descSuffix);
    builder.addCounter(metricsInfo, value);
}
Also used : MetricsInfo(org.apache.hadoop.metrics2.MetricsInfo)

Example 28 with MetricsRecordBuilder

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

the class StartupProgressMetrics method getMetrics.

@Override
public void getMetrics(MetricsCollector collector, boolean all) {
    StartupProgressView prog = startupProgress.createView();
    MetricsRecordBuilder builder = collector.addRecord(STARTUP_PROGRESS_METRICS_INFO);
    builder.addCounter(info("ElapsedTime", "overall elapsed time"), prog.getElapsedTime());
    builder.addGauge(info("PercentComplete", "overall percent complete"), prog.getPercentComplete());
    for (Phase phase : prog.getPhases()) {
        addCounter(builder, phase, "Count", " count", prog.getCount(phase));
        addCounter(builder, phase, "ElapsedTime", " elapsed time", prog.getElapsedTime(phase));
        addCounter(builder, phase, "Total", " total", prog.getTotal(phase));
        addGauge(builder, phase, "PercentComplete", " percent complete", prog.getPercentComplete(phase));
    }
}
Also used : Phase(org.apache.hadoop.hdfs.server.namenode.startupprogress.Phase) StartupProgressView(org.apache.hadoop.hdfs.server.namenode.startupprogress.StartupProgressView) MetricsRecordBuilder(org.apache.hadoop.metrics2.MetricsRecordBuilder)

Example 29 with MetricsRecordBuilder

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

the class StartupProgressMetrics method addGauge.

/**
   * Adds a gauge with a name built by using the specified phase's name as prefix
   * and then appending the specified suffix.
   * 
   * @param builder MetricsRecordBuilder to receive counter
   * @param phase Phase to add
   * @param nameSuffix String suffix of metric name
   * @param descSuffix String suffix of metric description
   * @param value float gauge value
   */
private static void addGauge(MetricsRecordBuilder builder, Phase phase, String nameSuffix, String descSuffix, float value) {
    MetricsInfo metricsInfo = info(phase.getName() + nameSuffix, phase.getDescription() + descSuffix);
    builder.addGauge(metricsInfo, value);
}
Also used : MetricsInfo(org.apache.hadoop.metrics2.MetricsInfo)

Example 30 with MetricsRecordBuilder

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

the class TestJournalNode method testJournal.

@Test(timeout = 100000)
public void testJournal() throws Exception {
    MetricsRecordBuilder metrics = MetricsAsserts.getMetrics(journal.getMetricsForTests().getName());
    MetricsAsserts.assertCounter("BatchesWritten", 0L, metrics);
    MetricsAsserts.assertCounter("BatchesWrittenWhileLagging", 0L, metrics);
    MetricsAsserts.assertGauge("CurrentLagTxns", 0L, metrics);
    MetricsAsserts.assertGauge("LastJournalTimestamp", 0L, metrics);
    long beginTimestamp = System.currentTimeMillis();
    IPCLoggerChannel ch = new IPCLoggerChannel(conf, FAKE_NSINFO, journalId, jn.getBoundIpcAddress());
    ch.newEpoch(1).get();
    ch.setEpoch(1);
    ch.startLogSegment(1, NameNodeLayoutVersion.CURRENT_LAYOUT_VERSION).get();
    ch.sendEdits(1L, 1, 1, "hello".getBytes(Charsets.UTF_8)).get();
    metrics = MetricsAsserts.getMetrics(journal.getMetricsForTests().getName());
    MetricsAsserts.assertCounter("BatchesWritten", 1L, metrics);
    MetricsAsserts.assertCounter("BatchesWrittenWhileLagging", 0L, metrics);
    MetricsAsserts.assertGauge("CurrentLagTxns", 0L, metrics);
    long lastJournalTimestamp = MetricsAsserts.getLongGauge("LastJournalTimestamp", metrics);
    assertTrue(lastJournalTimestamp > beginTimestamp);
    beginTimestamp = lastJournalTimestamp;
    ch.setCommittedTxId(100L);
    ch.sendEdits(1L, 2, 1, "goodbye".getBytes(Charsets.UTF_8)).get();
    metrics = MetricsAsserts.getMetrics(journal.getMetricsForTests().getName());
    MetricsAsserts.assertCounter("BatchesWritten", 2L, metrics);
    MetricsAsserts.assertCounter("BatchesWrittenWhileLagging", 1L, metrics);
    MetricsAsserts.assertGauge("CurrentLagTxns", 98L, metrics);
    lastJournalTimestamp = MetricsAsserts.getLongGauge("LastJournalTimestamp", metrics);
    assertTrue(lastJournalTimestamp > beginTimestamp);
}
Also used : IPCLoggerChannel(org.apache.hadoop.hdfs.qjournal.client.IPCLoggerChannel) 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