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.regionserver;
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  
27  import javax.servlet.http.HttpServletRequest;
28  import javax.servlet.http.HttpServletResponse;
29  
30  import org.apache.hadoop.hbase.classification.InterfaceAudience;
31  import org.apache.hadoop.conf.Configuration;
32  import org.apache.hadoop.hbase.monitoring.LogMonitoring;
33  import org.apache.hadoop.hbase.monitoring.StateDumpServlet;
34  import org.apache.hadoop.hbase.monitoring.TaskMonitor;
35  import org.apache.hadoop.hbase.util.Threads;
36  
37  @InterfaceAudience.Private
38  public class RSDumpServlet extends StateDumpServlet {
39    private static final long serialVersionUID = 1L;
40    private static final String LINE =
41      "===========================================================";
42  
43    @Override
44    public void doGet(HttpServletRequest request, HttpServletResponse response)
45        throws IOException {
46      HRegionServer hrs = (HRegionServer)getServletContext().getAttribute(
47          HRegionServer.REGIONSERVER);
48      assert hrs != null : "No RS in context!";
49      
50      Configuration hrsconf = (Configuration)getServletContext().getAttribute(
51          HRegionServer.REGIONSERVER_CONF);
52      assert hrsconf != null : "No RS conf in context";
53  
54      response.setContentType("text/plain");
55  
56      if (!hrs.isOnline()) {
57        response.getWriter().write("The RegionServer is initializing!");
58        response.getWriter().close();
59        return;
60      }
61  
62      OutputStream os = response.getOutputStream();
63      PrintWriter out = new PrintWriter(os);
64      
65      out.println("Master status for " + hrs.getServerName()
66          + " as of " + new Date());
67      
68      out.println("\n\nVersion Info:");
69      out.println(LINE);
70      dumpVersionInfo(out);
71  
72      out.println("\n\nTasks:");
73      out.println(LINE);
74      TaskMonitor.get().dumpAsText(out);
75      
76      out.println("\n\nExecutors:");
77      out.println(LINE);
78      dumpExecutors(hrs.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\nRS Configuration:");
87      out.println(LINE);
88      Configuration conf = hrs.getConfiguration();
89      out.flush();
90      conf.writeXml(os);
91      os.flush();
92      
93      out.println("\n\nLogs");
94      out.println(LINE);
95      long tailKb = getTailKbParam(request);
96      LogMonitoring.dumpTailOfLogs(out, tailKb);
97      
98      out.println("\n\nRS Queue:");
99      out.println(LINE);
100     if(isShowQueueDump(hrsconf)) {
101       dumpQueue(hrs, out);
102     } 
103     
104     out.flush();
105   }
106   
107   private boolean isShowQueueDump(Configuration conf){
108     return conf.getBoolean("hbase.regionserver.servlet.show.queuedump", true);
109   }
110     
111   private void dumpQueue(HRegionServer hrs, PrintWriter out)
112       throws IOException {
113     // 1. Print out Compaction/Split Queue
114     out.println("Compaction/Split Queue summary: " 
115         + hrs.compactSplitThread.toString() );
116     out.println(hrs.compactSplitThread.dumpQueue());
117 
118     // 2. Print out flush Queue
119     out.println("\nFlush Queue summary: "
120         + hrs.cacheFlusher.toString());
121     out.println(hrs.cacheFlusher.dumpQueue());
122   }
123   
124 }