You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2013/08/28 20:37:09 UTC

svn commit: r1518321 - in /activemq/trunk/activemq-console/src/main: java/org/apache/activemq/console/command/DstatCommand.java resources/META-INF/services/org.apache.activemq.console.command.Command

Author: tabish
Date: Wed Aug 28 18:37:09 2013
New Revision: 1518321

URL: http://svn.apache.org/r1518321
Log:
fix for: https://issues.apache.org/jira/browse/AMQ-4188

Adds dstat command

Added:
    activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/DstatCommand.java   (with props)
Modified:
    activemq/trunk/activemq-console/src/main/resources/META-INF/services/org.apache.activemq.console.command.Command

Added: activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/DstatCommand.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/DstatCommand.java?rev=1518321&view=auto
==============================================================================
--- activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/DstatCommand.java (added)
+++ activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/DstatCommand.java Wed Aug 28 18:37:09 2013
@@ -0,0 +1,176 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.console.command;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Locale;
+
+import javax.management.MBeanServerInvocationHandler;
+import javax.management.ObjectInstance;
+import javax.management.ObjectName;
+
+import org.apache.activemq.broker.jmx.QueueViewMBean;
+import org.apache.activemq.broker.jmx.TopicViewMBean;
+import org.apache.activemq.console.util.JmxMBeansUtil;
+
+public class DstatCommand extends AbstractJmxCommand {
+
+    private static final String queryString =
+        "type=Broker,brokerName=*,destinationType=%1,destinationName=*,*";
+
+    protected String[] helpFile = new String[] {
+        "Task Usage: activemq-admin dstat [dstat-options] [destination-type]",
+        "Description: Performs a predefined query that displays useful statistics regarding the specified .",
+        "             destination type (Queues or Topics) and displays those results in a tabular format.",
+        "             If no broker name is specified, it will try and select from all registered brokers.",
+        "",
+        "dstat Options:",
+        "    --jmxurl <url>                Set the JMX URL to connect to.",
+        "    --pid <pid>                   Set the pid to connect to (only on Sun JVM).",
+        "    --jmxuser <user>              Set the JMX user used for authenticating.",
+        "    --jmxpassword <password>      Set the JMX password used for authenticating.",
+        "    --jmxlocal                    Use the local JMX server instead of a remote one.",
+        "    --version                     Display the version information.",
+        "    -h,-?,--help                  Display the query broker help information.",
+        "",
+        "Examples:",
+        "    activemq-admin dstat queues",
+        "        - Display a tabular summary of statistics for the queues on the broker.",
+        "    activemq-admin dstat topics",
+        "        - Display a tabular summary of statistics for the queues on the broker."
+    };
+
+    /**
+     * Execute the dstat command, which allows you to display information for topics or queue in
+     * a tabular format.
+     *
+     * @param tokens - command arguments
+     * @throws Exception
+     */
+    @Override
+    protected void runTask(List<String> tokens) throws Exception {
+        try {
+
+            if (tokens.contains("topics")) {
+                displayTopicStats();
+            } else if (tokens.contains("queues")) {
+                displayQueueStats();
+            } else {
+                displayAllDestinations();
+            }
+
+            // Iterate through the queue names
+        } catch (Exception e) {
+            context.printException(new RuntimeException("Failed to execute dstat task. Reason: " + e));
+            throw new Exception(e);
+        }
+    }
+
+    private void displayAllDestinations() throws IOException, Exception {
+
+        String query = JmxMBeansUtil.createQueryString(queryString, "*");
+        List<?> queueList = JmxMBeansUtil.queryMBeans(createJmxConnection(), query);
+
+        final String header = "%20s  %10s  %10s  %10s  %10s";
+        final String tableRow = "%20s  %10d  %10d  %10d  %10d";
+
+        context.print(String.format(Locale.US, header, "Name", "Pending", "Consumers", "Enqueued", "Dequeued"));
+
+        // Iterate through the queue result
+        for (Object view : queueList) {
+            ObjectName queueName = ((ObjectInstance)view).getObjectName();
+            QueueViewMBean queueView = MBeanServerInvocationHandler.
+                newProxyInstance(createJmxConnection(), queueName, QueueViewMBean.class, true);
+
+            context.print(String.format(Locale.US, tableRow,
+                                        queueView.getName(),
+                                        queueView.getQueueSize(),
+                                        queueView.getConsumerCount(),
+                                        queueView.getEnqueueCount(),
+                                        queueView.getDequeueCount()));
+        }
+    }
+
+    private void displayQueueStats() throws IOException, Exception {
+
+        String query = JmxMBeansUtil.createQueryString(queryString, "Queue");
+        List<?> queueList = JmxMBeansUtil.queryMBeans(createJmxConnection(), query);
+
+        final String header = "%20s  %10s  %10s  %10s  %10s";
+        final String tableRow = "%20s  %10d  %10d  %10d  %10d";
+
+        context.print(String.format(Locale.US, header, "Name", "Pending", "Consumers", "Enqueued", "Dequeued"));
+
+        // Iterate through the queue result
+        for (Object view : queueList) {
+            ObjectName queueName = ((ObjectInstance)view).getObjectName();
+            QueueViewMBean queueView = MBeanServerInvocationHandler.
+                newProxyInstance(createJmxConnection(), queueName, QueueViewMBean.class, true);
+
+            context.print(String.format(Locale.US, tableRow,
+                                        queueView.getName(),
+                                        queueView.getQueueSize(),
+                                        queueView.getConsumerCount(),
+                                        queueView.getEnqueueCount(),
+                                        queueView.getDequeueCount()));
+        }
+    }
+
+    private void displayTopicStats() throws IOException, Exception {
+
+        String query = JmxMBeansUtil.createQueryString(queryString, "Topic");
+        List<?> topicsList = JmxMBeansUtil.queryMBeans(createJmxConnection(), query);
+
+        final String header = "%20s  %10s  %10s  %10s";
+        final String tableRow = "%20s  %10d  %10d  %10d";
+
+        context.print(String.format(Locale.US, header, "Name", "Consumers", "Enqueued", "Dequeued"));
+
+        // Iterate through the topics result
+        for (Object view : topicsList) {
+            ObjectName topicName = ((ObjectInstance)view).getObjectName();
+            TopicViewMBean topicView = MBeanServerInvocationHandler.
+                newProxyInstance(createJmxConnection(), topicName, TopicViewMBean.class, true);
+
+            context.print(String.format(Locale.US, tableRow,
+                                        topicView.getName(),
+                                        topicView.getConsumerCount(),
+                                        topicView.getEnqueueCount(),
+                                        topicView.getDequeueCount()));
+        }
+    }
+
+    @Override
+    public String getName() {
+        return "dstat";
+    }
+
+    @Override
+    public String getOneLineDescription() {
+        return "Performs a predefined query that displays useful tabular statistics regarding the specified destination type";
+    }
+
+    /**
+     * Print the help messages for this command
+     */
+    @Override
+    protected void printHelp() {
+        context.printHelp(helpFile);
+    }
+
+}
\ No newline at end of file

Propchange: activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/command/DstatCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/trunk/activemq-console/src/main/resources/META-INF/services/org.apache.activemq.console.command.Command
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-console/src/main/resources/META-INF/services/org.apache.activemq.console.command.Command?rev=1518321&r1=1518320&r2=1518321&view=diff
==============================================================================
--- activemq/trunk/activemq-console/src/main/resources/META-INF/services/org.apache.activemq.console.command.Command (original)
+++ activemq/trunk/activemq-console/src/main/resources/META-INF/services/org.apache.activemq.console.command.Command Wed Aug 28 18:37:09 2013
@@ -21,6 +21,7 @@ org.apache.activemq.console.command.List
 org.apache.activemq.console.command.AmqBrowseCommand
 org.apache.activemq.console.command.QueryCommand
 org.apache.activemq.console.command.BstatCommand
+org.apache.activemq.console.command.DstatCommand
 org.apache.activemq.console.command.EncryptCommand
 org.apache.activemq.console.command.DecryptCommand
 org.apache.activemq.console.command.StoreExportCommand