NameNodeMetrics { public void shutdown() { DefaultMetricsSystem.shutdown(); } NameNodeMetrics(String processName, String sessionId, int[] intervals,
      final JvmMetrics jvmMetrics); @Metric("Number of file system operations") long totalFileOps(); static NameNodeMetrics create(Configuration conf, NamenodeRole r); JvmMetrics getJvmMetrics(); void shutdown(); void incrGetBlockLocations(); void incrFilesCreated(); void incrCreateFileOps(); void incrFilesAppended(); void incrAddBlockOps(); void incrGetAdditionalDatanodeOps(); void incrFilesRenamed(); void incrFilesTruncated(); void incrFilesDeleted(long delta); void incrDeleteFileOps(); void incrGetListingOps(); void incrFilesInGetListingOps(int delta); void incrFileInfoOps(); void incrCreateSymlinkOps(); void incrGetLinkTargetOps(); void incrAllowSnapshotOps(); void incrDisAllowSnapshotOps(); void incrCreateSnapshotOps(); void incrDeleteSnapshotOps(); void incrRenameSnapshotOps(); void incrListSnapshottableDirOps(); void incrListSnapshotsOps(); void incrSnapshotDiffReportOps(); void incrBlockReceivedAndDeletedOps(); void setBlockOpsQueued(int size); void addBlockOpsBatched(int count); void addTransaction(long latency); void incrTransactionsBatchedInSync(long count); void incSuccessfulReReplications(); void incNumTimesReReplicationNotScheduled(); void incTimeoutReReplications(); void addSync(long elapsed); void setFsImageLoadTime(long elapsed); void addStorageBlockReport(long latency); void addCacheBlockReport(long latency); void setSafeModeTime(long elapsed); void addGetEdit(long latency); void addGetImage(long latency); void addGetAliasMap(long latency); void addPutImage(long latency); void addGenerateEDEKTime(long latency); void addWarmUpEDEKTime(long latency); void addResourceCheckTime(long latency); void addEditLogTailTime(long elapsed); void addEditLogFetchTime(long elapsed); void addNumEditLogLoaded(long loaded); void addEditLogTailInterval(long elapsed);  }
@Test(timeout = 300000) public void testTransactionSinceLastCheckpointMetrics() throws Exception { Random random = new Random(); int retryCount = 0; while (retryCount < 5) { try { int basePort = 10060 + random.nextInt(100) * 2; MiniDFSNNTopology topology = new MiniDFSNNTopology() .addNameservice(new MiniDFSNNTopology.NSConf("ns1") .addNN(new MiniDFSNNTopology.NNConf("nn1").setHttpPort(basePort)) .addNN(new MiniDFSNNTopology.NNConf("nn2").setHttpPort(basePort + 1))); HdfsConfiguration conf2 = new HdfsConfiguration(); conf2.setInt( DFSConfigKeys.DFS_NAMENODE_CHECKPOINT_TXNS_KEY, 100); conf2.setInt( DFSConfigKeys.DFS_NAMENODE_CHECKPOINT_CHECK_PERIOD_KEY, 1); conf2.setInt(DFSConfigKeys.DFS_HA_TAILEDITS_PERIOD_KEY, 1); MiniDFSCluster cluster2 = new MiniDFSCluster.Builder(conf2) .nnTopology(topology).numDataNodes(1).build(); cluster2.waitActive(); DistributedFileSystem fs2 = cluster2.getFileSystem(0); NameNode nn0 = cluster2.getNameNode(0); NameNode nn1 = cluster2.getNameNode(1); cluster2.transitionToActive(0); fs2.mkdirs(new Path("/tmp-t1")); fs2.mkdirs(new Path("/tmp-t2")); HATestUtil.waitForStandbyToCatchUp(nn0, nn1); assertEquals("SBN failed to track 2 transactions pre-checkpoint.", 4L, cluster2.getNameNode(1).getNamesystem() .getTransactionsSinceLastCheckpoint()); for (int i = 1; i <= 94; i++) { fs2.mkdirs(new Path("/tmp-" + i)); } HATestUtil.waitForStandbyToCatchUp(nn0, nn1); HATestUtil.waitForCheckpoint(cluster2, 1, ImmutableList.of(100)); assertEquals("Should be zero right after the checkpoint.", 0L, cluster2.getNameNode(1).getNamesystem() .getTransactionsSinceLastCheckpoint()); fs2.mkdirs(new Path("/tmp-t3")); fs2.mkdirs(new Path("/tmp-t4")); HATestUtil.waitForStandbyToCatchUp(nn0, nn1); assertEquals("SBN failed to track 2 added txns after the ckpt.", 4L, cluster2.getNameNode(1).getNamesystem() .getTransactionsSinceLastCheckpoint()); cluster2.shutdown(); break; } catch (Exception e) { LOG.warn("Unable to set up HA cluster, exception thrown: " + e); retryCount++; } } }
@Test public void testResourceCheck() throws Exception { HdfsConfiguration conf = new HdfsConfiguration(); File basedir = new File(MiniDFSCluster.getBaseDirectory(), GenericTestUtils.getMethodName()); MiniDFSCluster tmpCluster = new MiniDFSCluster.Builder(conf, basedir) .numDataNodes(0) .nnTopology(MiniDFSNNTopology.simpleHATopology()) .build(); try { MockNameNodeResourceChecker mockResourceChecker = new MockNameNodeResourceChecker(conf); tmpCluster.getNameNode(0).getNamesystem() .setNNResourceChecker(mockResourceChecker); NNHAServiceTarget haTarget = new NNHAServiceTarget(conf, DFSUtil.getNamenodeNameServiceId( new HdfsConfiguration()), "nn1"); HAServiceProtocol rpc = haTarget.getHealthMonitorProxy(conf, conf.getInt( HA_HM_RPC_TIMEOUT_KEY, HA_HM_RPC_TIMEOUT_DEFAULT)); MetricsRecordBuilder rb = getMetrics(NN_METRICS); for (long i = 0; i < 10; i++) { rpc.monitorHealth(); assertQuantileGauges("ResourceCheckTime1s", rb); } } finally { if (tmpCluster != null) { tmpCluster.shutdown(); } } }
@Test public void testEditLogTailing() throws Exception { HdfsConfiguration conf = new HdfsConfiguration(); conf.setInt(DFSConfigKeys.DFS_HA_TAILEDITS_PERIOD_KEY, 1); conf.setInt(DFSConfigKeys.DFS_METRICS_PERCENTILES_INTERVALS_KEY, 60); MiniDFSCluster dfsCluster = null; try { dfsCluster = new MiniDFSCluster.Builder(conf) .numDataNodes(0) .nnTopology(MiniDFSNNTopology.simpleHATopology()) .build(); DistributedFileSystem dfs = dfsCluster.getFileSystem(0); dfsCluster.transitionToActive(0); dfsCluster.waitActive(); Path testDir = new Path("/testdir"); dfs.mkdir(testDir, FsPermission.getDefault()); dfsCluster.getNameNodeRpc(0).rollEditLog(); Thread.sleep(2 * 1000); MetricsRecordBuilder rb = getMetrics(NN_METRICS+"-2"); assertQuantileGauges("EditLogTailTime60s", rb); assertQuantileGauges("EditLogFetchTime60s", rb); assertQuantileGauges("NumEditLogLoaded60s", rb, "Count"); assertQuantileGauges("EditLogTailInterval60s", rb); assertCounterGt("EditLogTailTimeNumOps", 0L, rb); assertCounterGt("EditLogFetchTimeNumOps", 0L, rb); assertCounterGt("NumEditLogLoadedNumOps", 0L, rb); assertCounterGt("EditLogTailIntervalNumOps", 0L, rb); } finally { if (dfsCluster != null) { dfsCluster.shutdown(); } } }