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      response.setContentType("text/plain");
51  
52      if (!hrs.isOnline()) {
53        response.getWriter().write("The RegionServer is initializing!");
54        response.getWriter().close();
55        return;
56      }
57  
58      OutputStream os = response.getOutputStream();
59      PrintWriter out = new PrintWriter(os);
60  
61      out.println("RegionServer status for " + hrs.getServerName()
62          + " as of " + new Date());
63  
64      out.println("\n\nVersion Info:");
65      out.println(LINE);
66      dumpVersionInfo(out);
67  
68      out.println("\n\nTasks:");
69      out.println(LINE);
70      TaskMonitor.get().dumpAsText(out);
71  
72      out.println("\n\nExecutors:");
73      out.println(LINE);
74      dumpExecutors(hrs.getExecutorService(), out);
75  
76      out.println("\n\nStacks:");
77      out.println(LINE);
78      PrintStream ps = new PrintStream(response.getOutputStream(), false, "UTF-8");
79      Threads.printThreadInfo(ps, "");
80      ps.flush();
81  
82      out.println("\n\nRS Configuration:");
83      out.println(LINE);
84      Configuration conf = hrs.getConfiguration();
85      out.flush();
86      conf.writeXml(os);
87      os.flush();
88  
89      out.println("\n\nLogs");
90      out.println(LINE);
91      long tailKb = getTailKbParam(request);
92      LogMonitoring.dumpTailOfLogs(out, tailKb);
93  
94      out.println("\n\nRS Queue:");
95      out.println(LINE);
96      if(isShowQueueDump(conf)) {
97        dumpQueue(hrs, out);
98      }
99  
100     out.flush();
101   }
102 
103   public static void dumpQueue(HRegionServer hrs, PrintWriter out)
104       throws IOException {
105     if (hrs.compactSplitThread != null) {
106       // 1. Print out Compaction/Split Queue
107       out.println("Compaction/Split Queue summary: "
108           + hrs.compactSplitThread.toString() );
109       out.println(hrs.compactSplitThread.dumpQueue());
110     }
111 
112     if (hrs.cacheFlusher != null) {
113       // 2. Print out flush Queue
114       out.println("\nFlush Queue summary: "
115           + hrs.cacheFlusher.toString());
116       out.println(hrs.cacheFlusher.dumpQueue());
117     }
118   }
119 }