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  import javax.servlet.http.HttpServletRequest;
27  import javax.servlet.http.HttpServletResponse;
28  
29  import org.apache.hadoop.hbase.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.hbase.util.Threads;
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      response.setContentType("text/plain");
50  
51      if (!hrs.isOnline()) {
52        response.getWriter().write("The RegionServer is initializing!");
53        response.getWriter().close();
54        return;
55      }
56  
57      OutputStream os = response.getOutputStream();
58      PrintWriter out = new PrintWriter(os);
59  
60      out.println("RegionServer status for " + hrs.getServerName()
61          + " as of " + new Date());
62  
63      out.println("\n\nVersion Info:");
64      out.println(LINE);
65      dumpVersionInfo(out);
66  
67      out.println("\n\nTasks:");
68      out.println(LINE);
69      TaskMonitor.get().dumpAsText(out);
70  
71      out.println("\n\nRowLocks:");
72      out.println(LINE);
73      dumpRowLock(hrs, 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      PrintStream ps = new PrintStream(response.getOutputStream(), false, "UTF-8");
82      Threads.printThreadInfo(ps, "");
83      ps.flush();
84  
85      out.println("\n\nRS Configuration:");
86      out.println(LINE);
87      Configuration conf = hrs.getConfiguration();
88      out.flush();
89      conf.writeXml(os);
90      os.flush();
91  
92      out.println("\n\nLogs");
93      out.println(LINE);
94      long tailKb = getTailKbParam(request);
95      LogMonitoring.dumpTailOfLogs(out, tailKb);
96  
97      out.println("\n\nRS Queue:");
98      out.println(LINE);
99      if(isShowQueueDump(conf)) {
100       dumpQueue(hrs, out);
101     }
102 
103     out.flush();
104   }
105 
106   public static void dumpRowLock(HRegionServer hrs, PrintWriter out) {
107     StringBuilder sb = new StringBuilder();
108     for (Region region : hrs.getOnlineRegionsLocalContext()) {
109       HRegion hRegion = (HRegion)region;
110       if (hRegion.getLockedRows().size() > 0) {
111         for (HRegion.RowLockContext rowLockContext : hRegion.getLockedRows().values()) {
112           sb.setLength(0);
113           sb.append(hRegion.getTableDesc().getTableName()).append(",")
114             .append(hRegion.getRegionInfo().getEncodedName()).append(",");
115           sb.append(rowLockContext.toString());
116           out.println(sb.toString());
117         }
118       }
119     }
120   }
121 
122   public static void dumpQueue(HRegionServer hrs, PrintWriter out)
123       throws IOException {
124     if (hrs.compactSplitThread != null) {
125       // 1. Print out Compaction/Split Queue
126       out.println("Compaction/Split Queue summary: "
127           + hrs.compactSplitThread.toString() );
128       out.println(hrs.compactSplitThread.dumpQueue());
129     }
130 
131     if (hrs.cacheFlusher != null) {
132       // 2. Print out flush Queue
133       out.println("\nFlush Queue summary: "
134           + hrs.cacheFlusher.toString());
135       out.println(hrs.cacheFlusher.dumpQueue());
136     }
137   }
138 }