From 3ec8258db67ef4c5afc35e71ca63435681cf9e87 Mon Sep 17 00:00:00 2001 From: Jonathan Ellis Date: Tue, 11 Aug 2009 20:40:10 +0000 Subject: [PATCH] expose threadpool's pendingtasks via nodeprobe. patch by Sammy Yu; reviewed by jbellis for CASSANDRA-360 git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/trunk@803285 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/cassandra/tools/NodeProbe.java | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/java/org/apache/cassandra/tools/NodeProbe.java b/src/java/org/apache/cassandra/tools/NodeProbe.java index 767adfe0c7..c09d55efe8 100644 --- a/src/java/org/apache/cassandra/tools/NodeProbe.java +++ b/src/java/org/apache/cassandra/tools/NodeProbe.java @@ -39,6 +39,7 @@ import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnectorFactory; import javax.management.remote.JMXServiceURL; +import org.apache.cassandra.concurrent.DebuggableThreadPoolExecutorMBean; import org.apache.cassandra.db.ColumnFamilyStoreMBean; import org.apache.cassandra.dht.Range; import org.apache.cassandra.net.EndPoint; @@ -452,6 +453,37 @@ public class NodeProbe ssProxy.clearSnapshot(); } + /** + * Print out the size of the queues in the thread pools + * + * @param outs Output stream to generate the output on. + */ + public void printThreadPoolStats(PrintStream outs) + { + ObjectName query; + try + { + query = new ObjectName("org.apache.cassandra.concurrent:type=*"); + Set result = mbeanServerConn.queryNames(query, null); + for (ObjectName objectName : result) + { + String poolName = objectName.getKeyProperty("type"); + DebuggableThreadPoolExecutorMBean threadPoolProxy = JMX.newMBeanProxy(mbeanServerConn, + objectName, + DebuggableThreadPoolExecutorMBean.class); + outs.println(poolName + ", pending tasks=" + threadPoolProxy.getPendingTasks()); + } + } + catch (MalformedObjectNameException e) + { + throw new RuntimeException("Invalid ObjectName? Please report this as a bug.", e); + } + catch (IOException e) + { + throw new RuntimeException("Could not retrieve list of stat mbeans.", e); + } + } + /** * Retrieve any non-option arguments passed on the command line. * @@ -481,7 +513,7 @@ public class NodeProbe { HelpFormatter hf = new HelpFormatter(); String header = String.format( - "%nAvailable commands: ring, cluster, info, cleanup, compact, cfstats, snapshot [name], clearsnapshot, bootstrap"); + "%nAvailable commands: ring, cluster, info, cleanup, compact, cfstats, snapshot [name], clearsnapshot, bootstrap, tpstats"); String usage = String.format("java %s -host %n", NodeProbe.class.getName()); hf.printHelp(usage, "", options, header); } @@ -569,6 +601,10 @@ public class NodeProbe System.exit(1); } } + else if (cmdName.equals("tpstats")) + { + probe.printThreadPoolStats(System.out); + } else { System.err.println("Unrecognized command: " + cmdName + ".");