001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.master.http; 019 020import java.io.IOException; 021import java.io.OutputStream; 022import java.io.PrintStream; 023import java.io.PrintWriter; 024import java.util.Date; 025import java.util.Map; 026import javax.servlet.http.HttpServletRequest; 027import javax.servlet.http.HttpServletResponse; 028import org.apache.hadoop.conf.Configuration; 029import org.apache.hadoop.hbase.ServerMetrics; 030import org.apache.hadoop.hbase.ServerName; 031import org.apache.hadoop.hbase.master.HMaster; 032import org.apache.hadoop.hbase.master.ServerManager; 033import org.apache.hadoop.hbase.master.assignment.AssignmentManager; 034import org.apache.hadoop.hbase.master.assignment.RegionStateNode; 035import org.apache.hadoop.hbase.monitoring.StateDumpServlet; 036import org.apache.hadoop.hbase.monitoring.TaskMonitor; 037import org.apache.hadoop.hbase.regionserver.http.RSDumpServlet; 038import org.apache.hadoop.hbase.util.LogMonitoring; 039import org.apache.hadoop.hbase.util.Threads; 040import org.apache.yetus.audience.InterfaceAudience; 041 042@InterfaceAudience.Private 043public class MasterDumpServlet extends StateDumpServlet { 044 private static final long serialVersionUID = 1L; 045 private static final String LINE = "==========================================================="; 046 047 @Override 048 public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { 049 HMaster master = (HMaster) getServletContext().getAttribute(HMaster.MASTER); 050 assert master != null : "No Master in context!"; 051 052 response.setContentType("text/plain"); 053 OutputStream os = response.getOutputStream(); 054 try (PrintWriter out = new PrintWriter(os)) { 055 056 out.println("Master status for " + master.getServerName() + " as of " + new Date()); 057 058 out.println("\n\nVersion Info:"); 059 out.println(LINE); 060 dumpVersionInfo(out); 061 062 out.println("\n\nTasks:"); 063 out.println(LINE); 064 TaskMonitor.get().dumpAsText(out); 065 066 out.println("\n\nServers:"); 067 out.println(LINE); 068 dumpServers(master, out); 069 070 out.println("\n\nRegions-in-transition:"); 071 out.println(LINE); 072 dumpRIT(master, out); 073 074 out.println("\n\nExecutors:"); 075 out.println(LINE); 076 dumpExecutors(master.getExecutorService(), out); 077 078 out.println("\n\nStacks:"); 079 out.println(LINE); 080 out.flush(); 081 PrintStream ps = new PrintStream(response.getOutputStream(), false, "UTF-8"); 082 Threads.printThreadInfo(ps, ""); 083 ps.flush(); 084 085 out.println("\n\nMaster configuration:"); 086 out.println(LINE); 087 Configuration conf = master.getConfiguration(); 088 out.flush(); 089 conf.writeXml(os); 090 os.flush(); 091 092 out.println("\n\nRecent regionserver aborts:"); 093 out.println(LINE); 094 master.getRegionServerFatalLogBuffer().dumpTo(out); 095 096 out.println("\n\nLogs"); 097 out.println(LINE); 098 long tailKb = getTailKbParam(request); 099 LogMonitoring.dumpTailOfLogs(out, tailKb); 100 101 out.println("\n\nRS Queue:"); 102 out.println(LINE); 103 if (isShowQueueDump(conf)) { 104 RSDumpServlet.dumpQueue(master, out); 105 } 106 out.flush(); 107 } 108 } 109 110 private void dumpRIT(HMaster master, PrintWriter out) { 111 AssignmentManager am = master.getAssignmentManager(); 112 if (am == null) { 113 out.println("AssignmentManager is not initialized"); 114 return; 115 } 116 117 for (RegionStateNode rs : am.getRegionsInTransition()) { 118 String rid = rs.getRegionInfo().getEncodedName(); 119 out.println("Region " + rid + ": " + rs.toDescriptiveString()); 120 } 121 } 122 123 private void dumpServers(HMaster master, PrintWriter out) { 124 ServerManager sm = master.getServerManager(); 125 if (sm == null) { 126 out.println("ServerManager is not initialized"); 127 return; 128 } 129 130 Map<ServerName, ServerMetrics> servers = sm.getOnlineServers(); 131 for (Map.Entry<ServerName, ServerMetrics> e : servers.entrySet()) { 132 out.println(e.getKey() + ": " + e.getValue()); 133 } 134 } 135}