dfshealth.jsp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <%@ page
  2. contentType="text/html; charset=UTF-8"
  3. import="javax.servlet.*"
  4. import="javax.servlet.http.*"
  5. import="java.io.*"
  6. import="java.util.*"
  7. import="org.apache.hadoop.dfs.*"
  8. import="java.text.DateFormat"
  9. %>
  10. <%!
  11. FSNamesystem fsn = FSNamesystem.getFSNamesystem();
  12. String namenodeLabel = fsn.getDFSNameNodeMachine() + ":" + fsn.getDFSNameNodePort();
  13. public void generateLiveNodeData(JspWriter out, DatanodeInfo d)
  14. throws IOException {
  15. long c = d.getCapacity();
  16. long r = d.getRemaining();
  17. long u = c - r;
  18. String cGb = DFSShell.limitDecimal((1.0 * c)/(1024*1024*1024), 2);
  19. String uGb = DFSShell.limitDecimal((1.0 * u)/(1024*1024*1024), 2);
  20. String percentUsed = DFSShell.limitDecimal(((1.0 * u)/c)*100, 2);
  21. out.print("<td style=\"vertical-align: top;\"> <b>" +
  22. d.getName().toString() +
  23. "</b>&nbsp;<br><i><b>LastContact:</b>" +
  24. new Date(d.lastUpdate())+ ";&nbsp;");
  25. out.print("<b>Total raw bytes:</b>&nbsp;" + c + "(" + cGb +
  26. "&nbsp;GB);&nbsp;");
  27. out.print("<b>Percent used:</b>&nbsp;" + percentUsed);
  28. out.print("</i></td>");
  29. }
  30. public void generateDFSHealthReport(JspWriter out) throws IOException {
  31. Vector live = new Vector();
  32. Vector dead = new Vector();
  33. fsn.DFSNodesStatus(live, dead);
  34. if (live.isEmpty() && dead.isEmpty()) {
  35. out.print("There are no datanodes in the cluster");
  36. }
  37. else {
  38. out.print("<table style=\"width: 100%; text-align: left;\" border=\"1\""+
  39. " cellpadding=\"2\" cellspacing=\"2\">");
  40. out.print("<tbody>");
  41. out.print("<tr>");
  42. out.print("<td style=\"vertical-align: top;\"><B>Live Nodes</B><br></td>");
  43. out.print("<td style=\"vertical-align: top;\"><B>Dead Nodes</B><br></td>");
  44. out.print("</tr>");
  45. int i = 0;
  46. int min = (live.size() > dead.size()) ? dead.size() : live.size();
  47. int max = (live.size() > dead.size()) ? live.size() : dead.size();
  48. for (i = 0; i < min; i++) {
  49. DatanodeInfo l = (DatanodeInfo)live.elementAt(i);
  50. DatanodeInfo d = (DatanodeInfo)dead.elementAt(i);
  51. out.print("<tr>");
  52. generateLiveNodeData(out, l);
  53. out.print("<td style=\"vertical-align: top;\">" +
  54. d.getName().toString() +
  55. "<br></td>");
  56. out.print("</tr>");
  57. }
  58. int type = (live.size() > dead.size()) ? 1 : 0;
  59. for (i = min; i < max; i++) {
  60. out.print("<tr>");
  61. if (type == 1) {
  62. DatanodeInfo l = (DatanodeInfo)live.elementAt(i);
  63. generateLiveNodeData(out, l);
  64. out.print("<td style=\"vertical-align: top;\"><br></td>");
  65. }
  66. else if (type == 0) {
  67. DatanodeInfo d = (DatanodeInfo)dead.elementAt(i);
  68. out.print("<td style=\"vertical-align: top;\"><br></td>");
  69. out.print("<td style=\"vertical-align: top;\">" +
  70. d.getName().toString() +
  71. "<br></td>");
  72. }
  73. out.print("</tr>");
  74. }
  75. out.print("</tbody></table>");
  76. }
  77. }
  78. public String totalCapacity() {
  79. return fsn.totalCapacity() + "(" + DFSShell.limitDecimal((1.0 * fsn.totalCapacity())/(1024*1024*1024), 2) + " GB)";
  80. }
  81. public String totalRemaining() {
  82. return fsn.totalRemaining() + "(" + DFSShell.limitDecimal(fsn.totalRemaining()/(1024*1024*1024), 2) + " GB)";
  83. }
  84. %>
  85. <html>
  86. <title>Hadoop DFS Health/Status</title>
  87. <body>
  88. <h1>NameNode '<%=namenodeLabel%>'</h1>
  89. This NameNode has been up since <%= fsn.getStartTime()%>.<br>
  90. <hr>
  91. <h2>Cluster Summary</h2>
  92. The capacity of this cluster is <%= totalCapacity()%> and remaining is <%= totalRemaining()%>.
  93. <%
  94. generateDFSHealthReport(out);
  95. %>
  96. <hr>
  97. <h2>Local logs</h2>
  98. <a href="/logs/">Log</a> directory
  99. <hr>
  100. <a href="http://lucene.apache.org/hadoop">Hadoop</a>, 2006.<br>
  101. </body>
  102. </html>