source: proiecte/HadoopJUnit/hadoop-0.20.1/src/webapps/hdfs/dfshealth.jsp @ 120

Last change on this file since 120 was 120, checked in by (none), 14 years ago

Added the mail files for the Hadoop JUNit Project

  • Property svn:executable set to *
File size: 10.1 KB
Line 
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.fs.*"
8  import="org.apache.hadoop.hdfs.*"
9  import="org.apache.hadoop.hdfs.server.namenode.*"
10  import="org.apache.hadoop.hdfs.server.datanode.*"
11  import="org.apache.hadoop.hdfs.server.common.Storage"
12  import="org.apache.hadoop.hdfs.server.common.Storage.StorageDirectory"
13  import="org.apache.hadoop.hdfs.protocol.*"
14  import="org.apache.hadoop.util.*"
15  import="java.text.DateFormat"
16  import="java.lang.Math"
17  import="java.net.URLEncoder"
18%>
19<%!
20  JspHelper jspHelper = new JspHelper();
21
22  int rowNum = 0;
23  int colNum = 0;
24
25  String rowTxt() { colNum = 0;
26      return "<tr class=\"" + (((rowNum++)%2 == 0)? "rowNormal" : "rowAlt")
27          + "\"> "; }
28  String colTxt() { return "<td id=\"col" + ++colNum + "\"> "; }
29  void counterReset () { colNum = 0; rowNum = 0 ; }
30
31  long diskBytes = 1024 * 1024 * 1024;
32  String diskByteStr = "GB";
33
34  String sorterField = null;
35  String sorterOrder = null;
36
37  String NodeHeaderStr(String name) {
38      String ret = "class=header";
39      String order = "ASC";
40      if ( name.equals( sorterField ) ) {
41          ret += sorterOrder;
42          if ( sorterOrder.equals("ASC") )
43              order = "DSC";
44      }
45      ret += " onClick=\"window.document.location=" +
46          "'/dfshealth.jsp?sorter/field=" + name + "&sorter/order=" +
47          order + "'\" title=\"sort on this column\"";
48     
49      return ret;
50  }
51     
52  public void generateNodeData( JspWriter out, DatanodeDescriptor d,
53                                    String suffix, boolean alive,
54                                    int nnHttpPort )
55    throws IOException {
56     
57    /* Say the datanode is dn1.hadoop.apache.org with ip 192.168.0.5
58       we use:
59       1) d.getHostName():d.getPort() to display.
60           Domain and port are stripped if they are common across the nodes.
61           i.e. "dn1"
62       2) d.getHost():d.Port() for "title".
63          i.e. "192.168.0.5:50010"
64       3) d.getHostName():d.getInfoPort() for url.
65          i.e. "http://dn1.hadoop.apache.org:50075/..."
66          Note that "d.getHost():d.getPort()" is what DFS clients use
67          to interact with datanodes.
68    */
69    // from nn_browsedfscontent.jsp:
70    String url = "http://" + d.getHostName() + ":" + d.getInfoPort() +
71                 "/browseDirectory.jsp?namenodeInfoPort=" +
72                 nnHttpPort + "&dir=" +
73                 URLEncoder.encode("/", "UTF-8");
74     
75    String name = d.getHostName() + ":" + d.getPort();
76    if ( !name.matches( "\\d+\\.\\d+.\\d+\\.\\d+.*" ) ) 
77        name = name.replaceAll( "\\.[^.:]*", "" );   
78    int idx = (suffix != null && name.endsWith( suffix )) ?
79        name.indexOf( suffix ) : -1;
80   
81    out.print( rowTxt() + "<td class=\"name\"><a title=\""
82               + d.getHost() + ":" + d.getPort() +
83               "\" href=\"" + url + "\">" +
84               (( idx > 0 ) ? name.substring(0, idx) : name) + "</a>" +
85               (( alive ) ? "" : "\n") );
86    if ( !alive )
87        return;
88   
89    long c = d.getCapacity();
90    long u = d.getDfsUsed();
91    long nu = d.getNonDfsUsed();
92    long r = d.getRemaining();
93    String percentUsed = StringUtils.limitDecimalTo2(d.getDfsUsedPercent());   
94    String percentRemaining = StringUtils.limitDecimalTo2(d.getRemainingPercent());   
95   
96    String adminState = (d.isDecommissioned() ? "Decommissioned" :
97                         (d.isDecommissionInProgress() ? "Decommission In Progress":
98                          "In Service"));
99   
100    long timestamp = d.getLastUpdate();
101    long currentTime = System.currentTimeMillis();
102    out.print("<td class=\"lastcontact\"> " +
103              ((currentTime - timestamp)/1000) +
104              "<td class=\"adminstate\">" +
105              adminState +
106              "<td align=\"right\" class=\"capacity\">" +
107              StringUtils.limitDecimalTo2(c*1.0/diskBytes) +
108              "<td align=\"right\" class=\"used\">" +
109              StringUtils.limitDecimalTo2(u*1.0/diskBytes) +     
110              "<td align=\"right\" class=\"nondfsused\">" +
111              StringUtils.limitDecimalTo2(nu*1.0/diskBytes) +     
112              "<td align=\"right\" class=\"remaining\">" +
113              StringUtils.limitDecimalTo2(r*1.0/diskBytes) +     
114              "<td align=\"right\" class=\"pcused\">" + percentUsed +
115              "<td class=\"pcused\">" +
116              ServletUtil.percentageGraph( (int)Double.parseDouble(percentUsed) , 100) +
117              "<td align=\"right\" class=\"pcremaining`\">" + percentRemaining +
118              "<td title=" + "\"blocks scheduled : " + d.getBlocksScheduled() + 
119              "\" class=\"blocks\">" + d.numBlocks() + "\n");
120  }
121 
122 
123  public void generateConfReport( JspWriter out,
124                  FSNamesystem fsn,
125                  HttpServletRequest request)
126  throws IOException {
127          long underReplicatedBlocks = fsn.getUnderReplicatedBlocks();
128          FSImage fsImage = fsn.getFSImage();
129          List<Storage.StorageDirectory> removedStorageDirs = fsImage.getRemovedStorageDirs();
130          String storageDirsSizeStr="", removedStorageDirsSizeStr="", storageDirsStr="", removedStorageDirsStr="", storageDirsDiv="", removedStorageDirsDiv="";
131
132          //FS Image storage configuration
133          out.print("<h3> NameNode Storage: </h3>");
134          out.print("<div id=\"dfstable\"> <table border=1 cellpadding=10 cellspacing=0 title=\"NameNode Storage\">\n"+
135          "<thead><tr><td><b>Storage Directory</b></td><td><b>Type</b></td><td><b>State</b></td></tr></thead>");
136         
137          StorageDirectory st =null;
138          for (Iterator<StorageDirectory> it = fsImage.dirIterator(); it.hasNext();) {
139              st = it.next();
140              String dir = "" +  st.getRoot();
141                  String type = "" + st.getStorageDirType();
142                  out.print("<tr><td>"+dir+"</td><td>"+type+"</td><td>Active</td></tr>");
143          }
144         
145          long storageDirsSize = removedStorageDirs.size();
146          for(int i=0; i< storageDirsSize; i++){
147                  st = removedStorageDirs.get(i);
148                  String dir = "" +  st.getRoot();
149                  String type = "" + st.getStorageDirType();
150                  out.print("<tr><td>"+dir+"</td><td>"+type+"</td><td><font color=red>Failed</font></td></tr>");
151          }
152         
153          out.print("</table></div><br>\n");
154  }
155
156
157  public void generateDFSHealthReport(JspWriter out,
158                                      NameNode nn,
159                                      HttpServletRequest request)
160                                      throws IOException {
161    FSNamesystem fsn = nn.getNamesystem();
162    ArrayList<DatanodeDescriptor> live = new ArrayList<DatanodeDescriptor>();
163    ArrayList<DatanodeDescriptor> dead = new ArrayList<DatanodeDescriptor>();
164    jspHelper.DFSNodesStatus(live, dead);
165
166    sorterField = request.getParameter("sorter/field");
167    sorterOrder = request.getParameter("sorter/order");
168    if ( sorterField == null )
169        sorterField = "name";
170    if ( sorterOrder == null )
171        sorterOrder = "ASC";
172
173    // Find out common suffix. Should this be before or after the sort?
174    String port_suffix = null;
175    if ( live.size() > 0 ) {
176        String name = live.get(0).getName();
177        int idx = name.indexOf(':');
178        if ( idx > 0 ) {
179            port_suffix = name.substring( idx );
180        }
181       
182        for ( int i=1; port_suffix != null && i < live.size(); i++ ) {
183            if ( live.get(i).getName().endsWith( port_suffix ) == false ) {
184                port_suffix = null;
185                break;
186            }
187        }
188    }
189       
190    counterReset();
191   
192    long total = fsn.getCapacityTotal();
193    long remaining = fsn.getCapacityRemaining();
194    long used = fsn.getCapacityUsed();
195    long nonDFS = fsn.getCapacityUsedNonDFS();
196    float percentUsed = fsn.getCapacityUsedPercent();
197    float percentRemaining = fsn.getCapacityRemainingPercent();
198
199    out.print( "<div id=\"dfstable\"> <table>\n" +
200               rowTxt() + colTxt() + "Configured Capacity" + colTxt() + ":" + colTxt() +
201               StringUtils.byteDesc( total ) +
202               rowTxt() + colTxt() + "DFS Used" + colTxt() + ":" + colTxt() +
203               StringUtils.byteDesc( used ) +
204               rowTxt() + colTxt() + "Non DFS Used" + colTxt() + ":" + colTxt() +
205               StringUtils.byteDesc( nonDFS ) +
206               rowTxt() + colTxt() + "DFS Remaining" + colTxt() + ":" + colTxt() +
207               StringUtils.byteDesc( remaining ) +
208               rowTxt() + colTxt() + "DFS Used%" + colTxt() + ":" + colTxt() +
209               StringUtils.limitDecimalTo2(percentUsed) + " %" +
210               rowTxt() + colTxt() + "DFS Remaining%" + colTxt() + ":" + colTxt() +
211               StringUtils.limitDecimalTo2(percentRemaining) + " %" +
212               rowTxt() + colTxt() +
213                        "<a href=\"dfsnodelist.jsp?whatNodes=LIVE\">Live Nodes</a> " +
214                        colTxt() + ":" + colTxt() + live.size() +
215               rowTxt() + colTxt() +
216                        "<a href=\"dfsnodelist.jsp?whatNodes=DEAD\">Dead Nodes</a> " +
217                        colTxt() + ":" + colTxt() + dead.size() +
218               "</table></div><br>\n" );
219   
220    if (live.isEmpty() && dead.isEmpty()) {
221        out.print("There are no datanodes in the cluster");
222    }
223  }%>
224
225<%
226  NameNode nn = (NameNode)application.getAttribute("name.node");
227  FSNamesystem fsn = nn.getNamesystem();
228  String namenodeLabel = nn.getNameNodeAddress().getHostName() + ":" + nn.getNameNodeAddress().getPort();
229%>
230
231<html>
232
233<link rel="stylesheet" type="text/css" href="/static/hadoop.css">
234<title>Hadoop NameNode <%=namenodeLabel%></title>
235   
236<body>
237<h1>NameNode '<%=namenodeLabel%>'</h1>
238
239
240<div id="dfstable"> <table>       
241<tr> <td id="col1"> Started: <td> <%= fsn.getStartTime()%>
242<tr> <td id="col1"> Version: <td> <%= VersionInfo.getVersion()%>, r<%= VersionInfo.getRevision()%>
243<tr> <td id="col1"> Compiled: <td> <%= VersionInfo.getDate()%> by <%= VersionInfo.getUser()%>
244<tr> <td id="col1"> Upgrades: <td> <%= jspHelper.getUpgradeStatusText()%>
245</table></div><br>                                   
246
247<b><a href="/nn_browsedfscontent.jsp">Browse the filesystem</a></b><br>
248<b><a href="/logs/">Namenode Logs</a></b>
249
250<hr>
251<h3>Cluster Summary</h3>
252<b> <%= jspHelper.getSafeModeText()%> </b>
253<b> <%= jspHelper.getInodeLimitText()%> </b>
254<a class="warning"> <%= JspHelper.getWarningText(fsn)%></a>
255
256<%
257    generateDFSHealthReport(out, nn, request); 
258%>
259<hr>
260<%
261        generateConfReport(out, fsn, request);
262%>
263<%
264out.println(ServletUtil.htmlFooter());
265%>
Note: See TracBrowser for help on using the repository browser.