NamenodeJspHelper { static String getInodeLimitText(FSNamesystem fsn) { if (fsn == null) { return ""; } long inodes = fsn.dir.totalInodes(); long blocks = fsn.getBlocksTotal(); long maxobjects = fsn.getMaxObjects(); MemoryMXBean mem = ManagementFactory.getMemoryMXBean(); MemoryUsage heap = mem.getHeapMemoryUsage(); long totalMemory = heap.getUsed(); long maxMemory = heap.getMax(); long commitedMemory = heap.getCommitted(); MemoryUsage nonHeap = mem.getNonHeapMemoryUsage(); long totalNonHeap = nonHeap.getUsed(); long maxNonHeap = nonHeap.getMax(); long commitedNonHeap = nonHeap.getCommitted(); long used = (totalMemory * 100) / commitedMemory; long usedNonHeap = (totalNonHeap * 100) / commitedNonHeap; String str = "<div>" + inodes + " files and directories, " + blocks + " blocks = " + (inodes + blocks) + " total"; if (maxobjects != 0) { long pct = ((inodes + blocks) * 100) / maxobjects; str += " / " + maxobjects + " (" + pct + "%)"; } str += ".</div>"; str += "<div>Heap Memory used " + StringUtils.byteDesc(totalMemory) + " is " + " " + used + "% of Commited Heap Memory " + StringUtils.byteDesc(commitedMemory) + ". Max Heap Memory is " + StringUtils.byteDesc(maxMemory) + ". </div>"; str += "<div>Non Heap Memory used " + StringUtils.byteDesc(totalNonHeap) + " is" + " " + usedNonHeap + "% of " + " Commited Non Heap Memory " + StringUtils.byteDesc(commitedNonHeap) + ". Max Non Heap Memory is " + StringUtils.byteDesc(maxNonHeap) + ".</div>"; return str; }    }
@Test(timeout = 15000) public void testGetInodeLimitText() { NameNode nameNode = cluster.getNameNode(); FSNamesystem fsn = nameNode.getNamesystem(); ImmutableSet<String> patterns = ImmutableSet.of("files and directories", "Heap Memory used", "Non Heap Memory used"); String line = NamenodeJspHelper.getInodeLimitText(fsn); for(String pattern: patterns) { assertTrue("testInodeLimitText error " + pattern, line.contains(pattern)); } }