View Javadoc

1   /**
2    * Copyright 2011 The Apache Software Foundation
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License.
19   */
20  package org.apache.hadoop.hbase.master;
21  
22  import java.io.IOException;
23  import java.io.OutputStream;
24  import java.io.PrintWriter;
25  import java.util.Date;
26  import java.util.Map;
27  import java.util.NavigableMap;
28  
29  import javax.servlet.http.HttpServletRequest;
30  import javax.servlet.http.HttpServletResponse;
31  
32  import org.apache.hadoop.conf.Configuration;
33  import org.apache.hadoop.hbase.HServerInfo;
34  import org.apache.hadoop.hbase.HServerLoad;
35  import org.apache.hadoop.hbase.ServerName;
36  import org.apache.hadoop.hbase.master.AssignmentManager.RegionState;
37  import org.apache.hadoop.hbase.monitoring.LogMonitoring;
38  import org.apache.hadoop.hbase.monitoring.StateDumpServlet;
39  import org.apache.hadoop.hbase.monitoring.TaskMonitor;
40  import org.apache.hadoop.util.ReflectionUtils;
41  
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      ReflectionUtils.printThreadInfo(out, "");
83      
84      out.println("\n\nMaster configuration:");
85      out.println(LINE);
86      Configuration conf = master.getConfiguration();
87      out.flush();
88      conf.writeXml(os);
89      os.flush();
90      
91      out.println("\n\nRecent regionserver aborts:");
92      out.println(LINE);
93      master.getRegionServerFatalLogBuffer().dumpTo(out);
94      
95      out.println("\n\nLogs");
96      out.println(LINE);
97      long tailKb = getTailKbParam(request);
98      LogMonitoring.dumpTailOfLogs(out, tailKb);
99      
100     out.flush();
101   }
102   
103 
104   private void dumpRIT(HMaster master, PrintWriter out) {
105     NavigableMap<String, RegionState> regionsInTransition =
106       master.getAssignmentManager().getRegionsInTransition();
107     for (Map.Entry<String, RegionState> e : regionsInTransition.entrySet()) {
108       String rid = e.getKey();
109       RegionState rs = e.getValue();
110       out.println("Region " + rid + ": " + rs.toDescriptiveString());
111     }
112   }
113 
114   private void dumpServers(HMaster master, PrintWriter out) {
115     Map<ServerName, HServerLoad> servers =
116       master.getServerManager().getOnlineServers();
117     for (Map.Entry<ServerName, HServerLoad> e : servers.entrySet()) {
118       out.println(e.getKey() + ": " + e.getValue());
119     }
120   }
121 }