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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 package org
.apache
.hadoop
.hbase
.master
;
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
;
27 import javax
.servlet
.http
.HttpServletRequest
;
28 import javax
.servlet
.http
.HttpServletResponse
;
29 import org
.apache
.hadoop
.conf
.Configuration
;
30 import org
.apache
.hadoop
.hbase
.ServerMetrics
;
31 import org
.apache
.hadoop
.hbase
.ServerName
;
32 import org
.apache
.hadoop
.hbase
.master
.assignment
.AssignmentManager
;
33 import org
.apache
.hadoop
.hbase
.master
.assignment
.RegionStateNode
;
34 import org
.apache
.hadoop
.hbase
.monitoring
.LogMonitoring
;
35 import org
.apache
.hadoop
.hbase
.monitoring
.StateDumpServlet
;
36 import org
.apache
.hadoop
.hbase
.monitoring
.TaskMonitor
;
37 import org
.apache
.hadoop
.hbase
.regionserver
.RSDumpServlet
;
38 import org
.apache
.hadoop
.hbase
.util
.Threads
;
39 import org
.apache
.yetus
.audience
.InterfaceAudience
;
41 @InterfaceAudience.Private
42 public class MasterDumpServlet
extends StateDumpServlet
{
43 private static final long serialVersionUID
= 1L;
44 private static final String LINE
=
45 "===========================================================";
48 public void doGet(HttpServletRequest request
, HttpServletResponse response
)
50 HMaster master
= (HMaster
) getServletContext().getAttribute(HMaster
.MASTER
);
51 assert master
!= null : "No Master in context!";
53 response
.setContentType("text/plain");
54 OutputStream os
= response
.getOutputStream();
55 try (PrintWriter out
= new PrintWriter(os
)) {
57 out
.println("Master status for " + master
.getServerName()
58 + " as of " + new Date());
60 out
.println("\n\nVersion Info:");
64 out
.println("\n\nTasks:");
66 TaskMonitor
.get().dumpAsText(out
);
68 out
.println("\n\nServers:");
70 dumpServers(master
, out
);
72 out
.println("\n\nRegions-in-transition:");
76 out
.println("\n\nExecutors:");
78 dumpExecutors(master
.getExecutorService(), out
);
80 out
.println("\n\nStacks:");
83 PrintStream ps
= new PrintStream(response
.getOutputStream(), false, "UTF-8");
84 Threads
.printThreadInfo(ps
, "");
87 out
.println("\n\nMaster configuration:");
89 Configuration conf
= master
.getConfiguration();
94 out
.println("\n\nRecent regionserver aborts:");
96 master
.getRegionServerFatalLogBuffer().dumpTo(out
);
98 out
.println("\n\nLogs");
100 long tailKb
= getTailKbParam(request
);
101 LogMonitoring
.dumpTailOfLogs(out
, tailKb
);
103 out
.println("\n\nRS Queue:");
105 if (isShowQueueDump(conf
)) {
106 RSDumpServlet
.dumpQueue(master
, out
);
113 private void dumpRIT(HMaster master
, PrintWriter out
) {
114 AssignmentManager am
= master
.getAssignmentManager();
116 out
.println("AssignmentManager is not initialized");
120 for (RegionStateNode rs
: am
.getRegionsInTransition()) {
121 String rid
= rs
.getRegionInfo().getEncodedName();
122 out
.println("Region " + rid
+ ": " + rs
.toDescriptiveString());
126 private void dumpServers(HMaster master
, PrintWriter out
) {
127 ServerManager sm
= master
.getServerManager();
129 out
.println("ServerManager is not initialized");
133 Map
<ServerName
, ServerMetrics
> servers
= sm
.getOnlineServers();
134 for (Map
.Entry
<ServerName
, ServerMetrics
> e
: servers
.entrySet()) {
135 out
.println(e
.getKey() + ": " + e
.getValue());