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   
54      if (!hrs.isOnline()) {
55        response.getWriter().write("The RegionServer is initializing!");
56        response.getWriter().close();
57        return;
58      }
59  
60      OutputStream os = response.getOutputStream();
61      PrintWriter out = new PrintWriter(os);
62      
63      out.println("Master status for " + hrs.getServerName()
64          + " as of " + new Date());
65      
66      out.println("\n\nVersion Info:");
67      out.println(LINE);
68      dumpVersionInfo(out);
69  
70      out.println("\n\nTasks:");
71      out.println(LINE);
72      TaskMonitor.get().dumpAsText(out);
73      
74      out.println("\n\nExecutors:");
75      out.println(LINE);
76      dumpExecutors(hrs.getExecutorService(), out);
77      
78      out.println("\n\nStacks:");
79      out.println(LINE);
80      ReflectionUtils.printThreadInfo(out, "");
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(hrsconf)) {
97        dumpQueue(hrs, out);
98      }
99      
100     out.flush();
101   }
102   
103   private boolean isShowQueueDump(Configuration conf){
104     return conf.getBoolean("hbase.regionserver.servlet.show.queuedump", true);
105   }
106   
107   private void dumpQueue(HRegionServer hrs, PrintWriter out)
108       throws IOException {
109     // 1. Print out Compaction/Split Queue
110     out.println("Compaction/Split Queue summary: " 
111         + hrs.compactSplitThread.toString() );
112     out.println(hrs.compactSplitThread.dumpQueue());
113 
114     // 2. Print out flush Queue
115     out.println("\nFlush Queue summary: "
116         + hrs.cacheFlusher.toString());
117     out.println(hrs.cacheFlusher.dumpQueue());
118   }
119   
120 }