View Javadoc

1   /**
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  package org.apache.hadoop.hbase.master;
20  
21  import java.io.IOException;
22  import java.io.OutputStream;
23  import java.io.PrintWriter;
24  import java.util.Date;
25  import java.util.Map;
26  
27  import javax.servlet.http.HttpServletRequest;
28  import javax.servlet.http.HttpServletResponse;
29  
30  import org.apache.hadoop.hbase.classification.InterfaceAudience;
31  import org.apache.hadoop.conf.Configuration;
32  import org.apache.hadoop.hbase.ServerLoad;
33  import org.apache.hadoop.hbase.ServerName;
34  import org.apache.hadoop.hbase.monitoring.LogMonitoring;
35  import org.apache.hadoop.hbase.monitoring.StateDumpServlet;
36  import org.apache.hadoop.hbase.monitoring.TaskMonitor;
37  import org.apache.hadoop.hbase.regionserver.RSDumpServlet;
38  import org.apache.hadoop.util.ReflectionUtils;
39  
40  @InterfaceAudience.Private
41  public class MasterDumpServlet extends StateDumpServlet {
42    private static final long serialVersionUID = 1L;
43    private static final String LINE =
44      "===========================================================";
45    
46    @Override
47    public void doGet(HttpServletRequest request, HttpServletResponse response)
48        throws IOException {
49      HMaster master = (HMaster) getServletContext().getAttribute(HMaster.MASTER);
50      assert master != null : "No Master in context!";
51  
52      response.setContentType("text/plain");
53      OutputStream os = response.getOutputStream();
54      PrintWriter out = new PrintWriter(os);
55      
56      out.println("Master status for " + master.getServerName()
57          + " as of " + new Date());
58      
59      out.println("\n\nVersion Info:");
60      out.println(LINE);
61      dumpVersionInfo(out);
62  
63      out.println("\n\nTasks:");
64      out.println(LINE);
65      TaskMonitor.get().dumpAsText(out);
66      
67      out.println("\n\nServers:");
68      out.println(LINE);
69      dumpServers(master, out);
70      
71      out.println("\n\nRegions-in-transition:");
72      out.println(LINE);
73      dumpRIT(master, out);
74      
75      out.println("\n\nExecutors:");
76      out.println(LINE);
77      dumpExecutors(master.getExecutorService(), out);
78      
79      out.println("\n\nStacks:");
80      out.println(LINE);
81      ReflectionUtils.printThreadInfo(out, "");
82      
83      out.println("\n\nMaster configuration:");
84      out.println(LINE);
85      Configuration conf = master.getConfiguration();
86      out.flush();
87      conf.writeXml(os);
88      os.flush();
89      
90      out.println("\n\nRecent regionserver aborts:");
91      out.println(LINE);
92      master.getRegionServerFatalLogBuffer().dumpTo(out);
93      
94      out.println("\n\nLogs");
95      out.println(LINE);
96      long tailKb = getTailKbParam(request);
97      LogMonitoring.dumpTailOfLogs(out, tailKb);
98  
99      out.println("\n\nRS Queue:");
100     out.println(LINE);
101     if(isShowQueueDump(conf)) {
102       RSDumpServlet.dumpQueue(master, out);
103     }
104     out.flush();
105   }
106   
107 
108   private void dumpRIT(HMaster master, PrintWriter out) {
109     AssignmentManager am = master.getAssignmentManager();
110     if (am == null) {
111       out.println("AssignmentManager is not initialized");
112       return;
113     }
114 
115     Map<String, RegionState> regionsInTransition =
116       am.getRegionStates().getRegionsInTransition();
117     for (Map.Entry<String, RegionState> e : regionsInTransition.entrySet()) {
118       String rid = e.getKey();
119       RegionState rs = e.getValue();
120       out.println("Region " + rid + ": " + rs.toDescriptiveString());
121     }
122   }
123 
124   private void dumpServers(HMaster master, PrintWriter out) {
125     ServerManager sm = master.getServerManager();
126     if (sm == null) {
127       out.println("ServerManager is not initialized");
128       return;
129     }
130 
131     Map<ServerName, ServerLoad> servers = sm.getOnlineServers();
132     for (Map.Entry<ServerName, ServerLoad> e : servers.entrySet()) {
133       out.println(e.getKey() + ": " + e.getValue());
134     }
135   }
136 }