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.PrintStream;
24  import java.io.PrintWriter;
25  import java.util.Date;
26  import java.util.Map;
27  
28  import javax.servlet.http.HttpServletRequest;
29  import javax.servlet.http.HttpServletResponse;
30  
31  import org.apache.hadoop.hbase.classification.InterfaceAudience;
32  import org.apache.hadoop.conf.Configuration;
33  import org.apache.hadoop.hbase.ServerLoad;
34  import org.apache.hadoop.hbase.ServerName;
35  import org.apache.hadoop.hbase.monitoring.LogMonitoring;
36  import org.apache.hadoop.hbase.monitoring.StateDumpServlet;
37  import org.apache.hadoop.hbase.monitoring.TaskMonitor;
38  import org.apache.hadoop.hbase.regionserver.RSDumpServlet;
39  import org.apache.hadoop.hbase.util.Threads;
40  
41  @InterfaceAudience.Private
42  public class MasterDumpServlet extends StateDumpServlet {
43    private static final long serialVersionUID = 1L;
44    private static final String LINE =
45      "===========================================================";
46  
47    @Override
48    public void doGet(HttpServletRequest request, HttpServletResponse response)
49        throws IOException {
50      HMaster master = (HMaster) getServletContext().getAttribute(HMaster.MASTER);
51      assert master != null : "No Master in context!";
52  
53      response.setContentType("text/plain");
54      OutputStream os = response.getOutputStream();
55      PrintWriter out = new PrintWriter(os);
56  
57      out.println("Master status for " + master.getServerName()
58          + " as of " + new Date());
59  
60      out.println("\n\nVersion Info:");
61      out.println(LINE);
62      dumpVersionInfo(out);
63  
64      out.println("\n\nTasks:");
65      out.println(LINE);
66      TaskMonitor.get().dumpAsText(out);
67  
68      out.println("\n\nServers:");
69      out.println(LINE);
70      dumpServers(master, out);
71  
72      out.println("\n\nRegions-in-transition:");
73      out.println(LINE);
74      dumpRIT(master, out);
75  
76      out.println("\n\nExecutors:");
77      out.println(LINE);
78      dumpExecutors(master.getExecutorService(), out);
79  
80      out.println("\n\nStacks:");
81      out.println(LINE);
82      PrintStream ps = new PrintStream(response.getOutputStream(), false, "UTF-8");
83      Threads.printThreadInfo(ps, "");
84      ps.flush();
85  
86      out.println("\n\nMaster configuration:");
87      out.println(LINE);
88      Configuration conf = master.getConfiguration();
89      out.flush();
90      conf.writeXml(os);
91      os.flush();
92  
93      out.println("\n\nRecent regionserver aborts:");
94      out.println(LINE);
95      master.getRegionServerFatalLogBuffer().dumpTo(out);
96  
97      out.println("\n\nLogs");
98      out.println(LINE);
99      long tailKb = getTailKbParam(request);
100     LogMonitoring.dumpTailOfLogs(out, tailKb);
101 
102     out.println("\n\nRS Queue:");
103     out.println(LINE);
104     if(isShowQueueDump(conf)) {
105       RSDumpServlet.dumpQueue(master, out);
106     }
107     out.flush();
108   }
109 
110 
111   private void dumpRIT(HMaster master, PrintWriter out) {
112     AssignmentManager am = master.getAssignmentManager();
113     if (am == null) {
114       out.println("AssignmentManager is not initialized");
115       return;
116     }
117 
118     Map<String, RegionState> regionsInTransition =
119       am.getRegionStates().getRegionsInTransition();
120     for (Map.Entry<String, RegionState> e : regionsInTransition.entrySet()) {
121       String rid = e.getKey();
122       RegionState rs = e.getValue();
123       out.println("Region " + rid + ": " + rs.toDescriptiveString());
124     }
125   }
126 
127   private void dumpServers(HMaster master, PrintWriter out) {
128     ServerManager sm = master.getServerManager();
129     if (sm == null) {
130       out.println("ServerManager is not initialized");
131       return;
132     }
133 
134     Map<ServerName, ServerLoad> servers = sm.getOnlineServers();
135     for (Map.Entry<ServerName, ServerLoad> e : servers.entrySet()) {
136       out.println(e.getKey() + ": " + e.getValue());
137     }
138   }
139 }