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.util.Threads;
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      PrintStream ps = new PrintStream(response.getOutputStream(), false, "UTF-8");
82      Threads.printThreadInfo(ps, "");
83      ps.flush();
84  
85      out.println("\n\nMaster configuration:");
86      out.println(LINE);
87      Configuration conf = master.getConfiguration();
88      out.flush();
89      conf.writeXml(os);
90      os.flush();
91  
92      out.println("\n\nRecent regionserver aborts:");
93      out.println(LINE);
94      master.getRegionServerFatalLogBuffer().dumpTo(out);
95  
96      out.println("\n\nLogs");
97      out.println(LINE);
98      long tailKb = getTailKbParam(request);
99      LogMonitoring.dumpTailOfLogs(out, tailKb);
100     
101     out.flush();
102   }
103 
104 
105   private void dumpRIT(HMaster master, PrintWriter out) {
106     Map<String, RegionState> regionsInTransition =
107       master.getAssignmentManager().getRegionStates().getRegionsInTransition();
108     for (Map.Entry<String, RegionState> e : regionsInTransition.entrySet()) {
109       String rid = e.getKey();
110       RegionState rs = e.getValue();
111       out.println("Region " + rid + ": " + rs.toDescriptiveString());
112     }
113   }
114 
115   private void dumpServers(HMaster master, PrintWriter out) {
116     Map<ServerName, ServerLoad> servers =
117       master.getServerManager().getOnlineServers();
118     for (Map.Entry<ServerName, ServerLoad> e : servers.entrySet()) {
119       out.println(e.getKey() + ": " + e.getValue());
120     }
121   }
122 }