NameNodeMetrics { public static NameNodeMetrics create(Configuration conf, NamenodeRole r) { String sessionId = conf.get(DFSConfigKeys.DFS_METRICS_SESSION_ID_KEY); String processName = r.toString(); MetricsSystem ms = DefaultMetricsSystem.instance(); JvmMetrics jm = JvmMetrics.create(processName, sessionId, ms); int[] intervals = conf.getInts(DFSConfigKeys.DFS_METRICS_PERCENTILES_INTERVALS_KEY); return ms.register(new NameNodeMetrics(processName, sessionId, intervals, jm)); } 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 incrSnapshotDiffReportOps(); void incrBlockReceivedAndDeletedOps(); void incrStorageBlockReportOps(); void setBlockOpsQueued(int size); void addBlockOpsBatched(int count); void addTransaction(long latency); void incrTransactionsBatchedInSync(); void addSync(long elapsed); void setFsImageLoadTime(long elapsed); void addBlockReport(long latency); void addCacheBlockReport(long latency); void setSafeModeTime(long elapsed); void addGetEdit(long latency); void addGetImage(long latency); void addPutImage(long latency);  }
@Test(timeout = 60000) public void testNumActiveClientsAndFilesUnderConstructionMetrics() throws Exception { final Path file1 = getTestPath("testFileAdd1"); createFile(file1, 100, (short) 3); assertGauge("NumActiveClients", 0L, getMetrics(NS_METRICS)); assertGauge("NumFilesUnderConstruction", 0L, getMetrics(NS_METRICS)); Path file2 = new Path("/testFileAdd2"); FSDataOutputStream output2 = fs.create(file2); output2.writeBytes("Some test data"); assertGauge("NumActiveClients", 1L, getMetrics(NS_METRICS)); assertGauge("NumFilesUnderConstruction", 1L, getMetrics(NS_METRICS)); Path file3 = new Path("/testFileAdd3"); FSDataOutputStream output3 = fs.create(file3); output3.writeBytes("Some test data"); assertGauge("NumActiveClients", 1L, getMetrics(NS_METRICS)); assertGauge("NumFilesUnderConstruction", 2L, getMetrics(NS_METRICS)); DistributedFileSystem fs1 = (DistributedFileSystem) cluster .getNewFileSystemInstance(0); try { Path file4 = new Path("/testFileAdd4"); FSDataOutputStream output4 = fs1.create(file4); output4.writeBytes("Some test data"); assertGauge("NumActiveClients", 2L, getMetrics(NS_METRICS)); assertGauge("NumFilesUnderConstruction", 3L, getMetrics(NS_METRICS)); Path file5 = new Path("/testFileAdd35"); FSDataOutputStream output5 = fs1.create(file5); output5.writeBytes("Some test data"); assertGauge("NumActiveClients", 2L, getMetrics(NS_METRICS)); assertGauge("NumFilesUnderConstruction", 4L, getMetrics(NS_METRICS)); output2.close(); output3.close(); assertGauge("NumActiveClients", 1L, getMetrics(NS_METRICS)); assertGauge("NumFilesUnderConstruction", 2L, getMetrics(NS_METRICS)); output4.close(); output5.close(); assertGauge("NumActiveClients", 0L, getMetrics(NS_METRICS)); assertGauge("NumFilesUnderConstruction", 0L, getMetrics(NS_METRICS)); } finally { fs1.close(); } }