001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.activemq.console.command;
018    
019    import java.util.ArrayList;
020    import java.util.Iterator;
021    import java.util.List;
022    
023    public class BstatCommand extends QueryCommand {
024    
025        protected String[] helpFile = new String[] {
026            "Task Usage: activemq-admin bstat [bstat-options] [broker-name]",
027            "Description: Performs a predefined query that displays useful statistics regarding the specified broker.",
028            "             If no broker name is specified, it will try and select from all registered brokers.",
029            "",
030            "Bstat Options:",
031            "    --jmxurl <url>                Set the JMX URL to connect to.",
032            "    --pid <pid>                   Set the pid to connect to (only on Sun JVM).",            
033            "    --jmxuser <user>              Set the JMX user used for authenticating.",
034            "    --jmxpassword <password>      Set the JMX password used for authenticating.",
035            "    --jmxlocal                    Use the local JMX server instead of a remote one.",
036            "    --version                     Display the version information.",
037            "    -h,-?,--help                  Display the query broker help information.",
038            "",
039            "Examples:",
040            "    activemq-admin bstat localhost",
041            "        - Display a summary of statistics for the broker 'localhost'"
042        };
043    
044        @Override
045        public String getName() {
046            return "bstat";
047        }
048    
049        @Override
050        public String getOneLineDescription() {
051            return "Performs a predefined query that displays useful statistics regarding the specified broker";
052        }
053    
054        /**
055         * Performs a predefiend query option
056         * @param tokens - command arguments
057         * @throws Exception
058         */
059        protected void runTask(List<String> tokens) throws Exception {
060            List<String> queryTokens = new ArrayList<String>();
061            // Find the first non-option token
062            String brokerName = "*";
063            for (Iterator i = tokens.iterator(); i.hasNext();) {
064                String token = (String)i.next();
065                if (!token.startsWith("-")) {
066                    brokerName = token;
067                    break;
068                } else {
069                    // Re-insert options
070                    queryTokens.add(token);
071                }
072            }
073    
074            // Build the predefined option
075            queryTokens.add("--objname");
076            queryTokens.add("type=*,brokerName=" + brokerName + ",*");
077            queryTokens.add("-xQTopic=ActiveMQ.Advisory.*");
078            queryTokens.add("--view");
079            queryTokens.add("BrokerName,Name,connectorName,networkConnectorName,destinationName,destinationType,EnqueueCount,"
080                            + "DequeueCount,TotalEnqueueCount,TotalDequeueCount,Messages,"
081                            + "TotalMessageCount,ConsumerCount,TotalConsumerCount,DispatchCount,Duplex,NetworkTTL");
082    
083            // Call the query command
084            super.parseOptions(queryTokens);
085            super.runTask(queryTokens);
086        }
087    
088        /**
089         * Print the help messages for the browse command
090         */
091        protected void printHelp() {
092            context.printHelp(helpFile);
093        }
094    
095    }