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