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 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 = 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(); } }