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      out.flush();
83      PrintStream ps = new PrintStream(response.getOutputStream(), false, "UTF-8");
84      Threads.printThreadInfo(ps, "");
85      ps.flush();
86  
87      out.println("\n\nMaster configuration:");
88      out.println(LINE);
89      Configuration conf = master.getConfiguration();
90      out.flush();
91      conf.writeXml(os);
92      os.flush();
93  
94      out.println("\n\nRecent regionserver aborts:");
95      out.println(LINE);
96      master.getRegionServerFatalLogBuffer().dumpTo(out);
97  
98      out.println("\n\nLogs");
99      out.println(LINE);
100     long tailKb = getTailKbParam(request);
101     LogMonitoring.dumpTailOfLogs(out, tailKb);
102 
103     out.println("\n\nRS Queue:");
104     out.println(LINE);
105     if(isShowQueueDump(conf)) {
106       RSDumpServlet.dumpQueue(master, out);
107     }
108     out.flush();
109   }
110 
111 
112   private void dumpRIT(HMaster master, PrintWriter out) {
113     AssignmentManager am = master.getAssignmentManager();
114     if (am == null) {
115       out.println("AssignmentManager is not initialized");
116       return;
117     }
118 
119     Map<String, RegionState> regionsInTransition =
120       am.getRegionStates().getRegionsInTransition();
121     for (Map.Entry<String, RegionState> e : regionsInTransition.entrySet()) {
122       String rid = e.getKey();
123       RegionState rs = e.getValue();
124       out.println("Region " + rid + ": " + rs.toDescriptiveString());
125     }
126   }
127 
128   private void dumpServers(HMaster master, PrintWriter out) {
129     ServerManager sm = master.getServerManager();
130     if (sm == null) {
131       out.println("ServerManager is not initialized");
132       return;
133     }
134 
135     Map<ServerName, ServerLoad> servers = sm.getOnlineServers();
136     for (Map.Entry<ServerName, ServerLoad> e : servers.entrySet()) {
137       out.println(e.getKey() + ": " + e.getValue());
138     }
139   }
140 }