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.regionserver.http; 019 020import java.io.IOException; 021import java.io.OutputStream; 022import java.io.PrintStream; 023import java.io.PrintWriter; 024import java.util.Date; 025import javax.servlet.http.HttpServletRequest; 026import javax.servlet.http.HttpServletResponse; 027import org.apache.hadoop.conf.Configuration; 028import org.apache.hadoop.hbase.http.HttpServer; 029import org.apache.hadoop.hbase.ipc.CallQueueInfo; 030import org.apache.hadoop.hbase.monitoring.StateDumpServlet; 031import org.apache.hadoop.hbase.monitoring.TaskMonitor; 032import org.apache.hadoop.hbase.regionserver.CompactSplit; 033import org.apache.hadoop.hbase.regionserver.HRegionServer; 034import org.apache.hadoop.hbase.regionserver.MemStoreFlusher; 035import org.apache.hadoop.hbase.util.LogMonitoring; 036import org.apache.hadoop.hbase.util.Threads; 037import org.apache.yetus.audience.InterfaceAudience; 038 039@InterfaceAudience.Private 040public class RSDumpServlet extends StateDumpServlet { 041 private static final long serialVersionUID = 1L; 042 private static final String LINE = "==========================================================="; 043 044 @Override 045 public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { 046 if (!HttpServer.isInstrumentationAccessAllowed(getServletContext(), request, response)) { 047 return; 048 } 049 HRegionServer hrs = 050 (HRegionServer) getServletContext().getAttribute(HRegionServer.REGIONSERVER); 051 assert hrs != null : "No RS in context!"; 052 053 response.setContentType("text/plain"); 054 055 if (!hrs.isOnline()) { 056 response.getWriter().write("The RegionServer is initializing!"); 057 response.getWriter().close(); 058 return; 059 } 060 061 OutputStream os = response.getOutputStream(); 062 try (PrintWriter out = new PrintWriter(os)) { 063 064 out.println("RegionServer status for " + hrs.getServerName() + " as of " + new Date()); 065 066 out.println("\n\nVersion Info:"); 067 out.println(LINE); 068 dumpVersionInfo(out); 069 070 out.println("\n\nTasks:"); 071 out.println(LINE); 072 TaskMonitor.get().dumpAsText(out); 073 074 out.println("\n\nRowLocks:"); 075 out.println(LINE); 076 hrs.dumpRowLocks(out); 077 078 out.println("\n\nExecutors:"); 079 out.println(LINE); 080 dumpExecutors(hrs.getExecutorService(), out); 081 082 out.println("\n\nStacks:"); 083 out.println(LINE); 084 PrintStream ps = new PrintStream(response.getOutputStream(), false, "UTF-8"); 085 Threads.printThreadInfo(ps, ""); 086 ps.flush(); 087 088 out.println("\n\nRS Configuration:"); 089 out.println(LINE); 090 Configuration conf = hrs.getConfiguration(); 091 out.flush(); 092 conf.writeXml(os); 093 os.flush(); 094 095 out.println("\n\nLogs"); 096 out.println(LINE); 097 long tailKb = getTailKbParam(request); 098 LogMonitoring.dumpTailOfLogs(out, tailKb); 099 100 out.println("\n\nRS Queue:"); 101 out.println(LINE); 102 if (isShowQueueDump(conf)) { 103 dumpQueue(hrs, out); 104 } 105 106 out.println("\n\nCall Queue Summary:"); 107 out.println(LINE); 108 dumpCallQueues(hrs, out); 109 110 out.flush(); 111 } 112 } 113 114 public static void dumpQueue(HRegionServer hrs, PrintWriter out) { 115 final CompactSplit compactSplit = hrs.getCompactSplitThread(); 116 if (compactSplit != null) { 117 // 1. Print out Compaction/Split Queue 118 out.println("Compaction/Split Queue summary: " + compactSplit); 119 out.println(compactSplit.dumpQueue()); 120 } 121 122 final MemStoreFlusher memStoreFlusher = hrs.getMemStoreFlusher(); 123 if (memStoreFlusher != null) { 124 // 2. Print out flush Queue 125 out.println(); 126 out.println("Flush Queue summary: " + memStoreFlusher); 127 out.println(memStoreFlusher.dumpQueue()); 128 } 129 } 130 131 public static void dumpCallQueues(HRegionServer hrs, PrintWriter out) { 132 CallQueueInfo callQueueInfo = hrs.getRpcServer().getScheduler().getCallQueueInfo(); 133 134 for (String queueName : callQueueInfo.getCallQueueNames()) { 135 136 out.println("\nQueue Name: " + queueName); 137 138 long totalCallCount = 0L, totalCallSize = 0L; 139 for (String methodName : callQueueInfo.getCalledMethodNames(queueName)) { 140 long thisMethodCount, thisMethodSize; 141 thisMethodCount = callQueueInfo.getCallMethodCount(queueName, methodName); 142 thisMethodSize = callQueueInfo.getCallMethodSize(queueName, methodName); 143 144 out.println("Method in call: " + methodName); 145 out.println("Total call count for method: " + thisMethodCount); 146 out.println("Total call size for method (bytes): " + thisMethodSize); 147 148 totalCallCount += thisMethodCount; 149 totalCallSize += thisMethodSize; 150 } 151 out.println("Total call count for queue: " + totalCallCount); 152 out.println("Total call size for queue (bytes): " + totalCallSize); 153 } 154 } 155}