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      response.setContentType("text/plain");
49      OutputStream os = response.getOutputStream();
50      PrintWriter out = new PrintWriter(os);
51      
52      out.println("Master status for " + hrs.getServerName()
53          + " as of " + new Date());
54      
55      out.println("\n\nVersion Info:");
56      out.println(LINE);
57      dumpVersionInfo(out);
58  
59      out.println("\n\nTasks:");
60      out.println(LINE);
61      TaskMonitor.get().dumpAsText(out);
62      
63      out.println("\n\nExecutors:");
64      out.println(LINE);
65      dumpExecutors(hrs.getExecutorService(), out);
66      
67      out.println("\n\nStacks:");
68      out.println(LINE);
69      ReflectionUtils.printThreadInfo(out, "");
70      
71      out.println("\n\nRS Configuration:");
72      out.println(LINE);
73      Configuration conf = hrs.getConfiguration();
74      out.flush();
75      conf.writeXml(os);
76      os.flush();
77      
78      out.println("\n\nLogs");
79      out.println(LINE);
80      long tailKb = getTailKbParam(request);
81      LogMonitoring.dumpTailOfLogs(out, tailKb);
82      
83      out.flush();
84    }  
85  }