From e16e400afbf8777056b1cbca47f716dc8a4cc34d Mon Sep 17 00:00:00 2001 From: William Au Date: Tue, 2 May 2006 17:38:11 +0000 Subject: [PATCH] first working version git-svn-id: https://svn.apache.org/repos/asf/incubator/solr/trunk@398974 13f79535-47bb-0310-9956-ffa450edef68 --- .../resources/admin/distributiondump.jsp | 81 ++++++++++++-- src/webapp/resources/admin/threaddump.jsp | 105 ++++++++++++++++-- 2 files changed, 167 insertions(+), 19 deletions(-) diff --git a/src/webapp/resources/admin/distributiondump.jsp b/src/webapp/resources/admin/distributiondump.jsp index 222de9bfd68..01a4f608019 100644 --- a/src/webapp/resources/admin/distributiondump.jsp +++ b/src/webapp/resources/admin/distributiondump.jsp @@ -2,6 +2,7 @@ org.apache.solr.schema.IndexSchema, java.io.BufferedReader, java.io.File, + java.io.FilenameFilter, java.io.FileReader, java.net.InetAddress, java.net.UnknownHostException, @@ -10,15 +11,16 @@ <%@include file="header.jsp" %> <% - File slaveinfo = new File(cwd + "/logs/snappuller.status"); + File slaveinfo = new File(cwd + "/solr/logs/snappuller.status"); StringBuffer buffer = new StringBuffer(); + StringBuffer buffer2 = new StringBuffer(); String mode = ""; if (slaveinfo.canRead()) { // Slave instance mode = "Slave"; - File slavevers = new File(cwd + "/logs/snapshot.current"); + File slavevers = new File(cwd + "/solr/logs/snapshot.current"); BufferedReader inforeader = new BufferedReader(new FileReader(slaveinfo)); BufferedReader versreader = new BufferedReader(new FileReader(slavevers)); buffer.append("\n" + @@ -41,8 +43,18 @@ } else { // Master instance mode = "Master"; - File masterdir = new File(cwd + "/logs/clients"); - File[] clients = masterdir.listFiles(); + File masterdir = new File(cwd + "/solr/logs/clients"); + FilenameFilter sfilter = new FilenameFilter() { + public boolean accept(File dir, String name) { + return name.startsWith("snapshot.status"); + } + }; + FilenameFilter cfilter = new FilenameFilter() { + public boolean accept(File dir, String name) { + return name.startsWith("snapshot.current"); + } + }; + File[] clients = masterdir.listFiles(cfilter); if (clients == null) { buffer.append("\n" + "\n" + @@ -52,19 +64,24 @@ "\n" + "\n"); } else { + buffer.append("

Client Snapshot In Use:

\n" + + "\n" + + "\n" + + "Client" + + "\n" + + "\n" + + "Version" + + "\n" + + "\n"); int i = 0; while (i < clients.length) { + String fileName=clients[i].toString(); + int p=fileName.indexOf("snapshot.current"); + String clientName=fileName.substring(p+17); BufferedReader reader = new BufferedReader(new FileReader(clients[i])); buffer.append("\n" + "\n" + - "Client:" + - "\n" + - "\n") - .append( clients[i].toString()) - .append( "\n" + - "\n" + - "\n" + - "\n" + + clientName + "\n" + "\n") .append( reader.readLine()) @@ -74,10 +91,50 @@ "\n"); i++; } + clients = masterdir.listFiles(sfilter); + if (clients!=null) { + buffer.append("\n" + + "

Client Snapshot Distribution Status:

\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n"); + i = 0; + while (i < clients.length) { + String fileName=clients[i].toString(); + int p=fileName.indexOf("snapshot.status"); + String clientName=fileName.substring(p+16); + BufferedReader reader = new BufferedReader(new FileReader(clients[i])); + buffer.append("\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n"); + i++; + } + } } } %> +
+

Distribution Info

+

<%= mode %> Server

+
\n" + + "Client" + + "\n" + + "Status" + + "
\n" + + clientName + + "\n") + .append( reader.readLine()) + .append( "
+<%= buffer %> +
+

+ Return to Admin Page diff --git a/src/webapp/resources/admin/threaddump.jsp b/src/webapp/resources/admin/threaddump.jsp index bc769fdf52b..57f809c1938 100644 --- a/src/webapp/resources/admin/threaddump.jsp +++ b/src/webapp/resources/admin/threaddump.jsp @@ -1,13 +1,104 @@ -<%@ page import="java.io.BufferedReader, - java.io.FileReader"%> -<%@ page import="java.util.Date"%> +<%@ page import="java.lang.management.ManagementFactory, + java.lang.management.ThreadMXBean, + java.lang.management.ThreadInfo, + java.io.IOException"%> <%@include file="header.jsp" %> -<% - File getinfo = new File("logs/jvm.log"); +<%! + static ThreadMXBean tmbean = ManagementFactory.getThreadMXBean(); %>
+

Thread Dump

+ + + + + + + + + + + + + +
+<% + out.print(System.getProperty("java.vm.name") + + " " + System.getProperty("java.vm.version") + "
"); +%> +
+<% + long[] tids; + ThreadInfo[] tinfos; -WORK IN PROGRESS: portable thread dump isn't implemented yet. - + out.print("Thread Count: current=" + tmbean.getThreadCount() + + " deamon=" + tmbean.getDaemonThreadCount() + + " peak=" + tmbean.getPeakThreadCount()); +%> +
+<% + tids = tmbean.findMonitorDeadlockedThreads(); + if (tids == null) { + out.print("No deadlock found."); + } + else { + out.print("Deadlock found :-"); + tinfos = tmbean.getThreadInfo(tids, Integer.MAX_VALUE); + for (ThreadInfo ti : tinfos) { + printThreadInfo(ti, out); + } + } +%> +
+<% + out.print("Full Thread Dump:
"); + tids = tmbean.getAllThreadIds(); + tinfos = tmbean.getThreadInfo(tids, Integer.MAX_VALUE); + for (ThreadInfo ti : tinfos) { + printThreadInfo(ti, out); + } +%> +
+

+ Return to Admin Page + +<%! + static String INDENT = "     "; + + static void printThreadInfo(ThreadInfo ti, JspWriter out) throws IOException { + long tid = ti.getThreadId(); + StringBuilder sb = new StringBuilder("\"" + ti.getThreadName() + "\"" + + " Id=" + tid + + " in " + ti.getThreadState()); + if (ti.getLockName() != null) { + sb.append(" on lock=" + ti.getLockName()); + } + if (ti.isSuspended()) { + sb.append(" (suspended)"); + } + if (ti.isInNative()) { + sb.append(" (running in native)"); + } + if (tmbean.isThreadCpuTimeSupported()) { + sb.append(" total cpu time=" + +formatNanos(tmbean.getThreadCpuTime(tid))); + sb.append(" user time=" + +formatNanos(tmbean.getThreadUserTime(tid))); + } + out.print(sb.toString()+"
"); + if (ti.getLockOwnerName() != null) { + out.print(INDENT + " owned by " + ti.getLockOwnerName() + + " Id=" + ti.getLockOwnerId()+"
"); + } + for (StackTraceElement ste : ti.getStackTrace()) { + out.print(INDENT + "at " + ste.toString()+"
"); + } + out.print("
"); + } + + static String formatNanos(long ns) { + return String.format("%.4fms", ns / (double) 1000000); + } +%>