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