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