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        @Override
060        protected void runTask(List<String> tokens) throws Exception {
061            List<String> queryTokens = new ArrayList<String>();
062            // Find the first non-option token
063            String brokerName = "*";
064            for (Iterator<String> i = tokens.iterator(); i.hasNext();) {
065                String token = i.next();
066                if (!token.startsWith("-")) {
067                    brokerName = token;
068                    break;
069                } else {
070                    // Re-insert options
071                    queryTokens.add(token);
072                }
073            }
074    
075            // Build the predefined option
076            queryTokens.add("--objname");
077            queryTokens.add("type=*,brokerName=" + brokerName + ",*");
078            queryTokens.add("-xQTopic=ActiveMQ.Advisory.*");
079            queryTokens.add("--view");
080            queryTokens.add("BrokerName,Name,connectorName,networkConnectorName,destinationName,destinationType,EnqueueCount,"
081                            + "DequeueCount,TotalEnqueueCount,TotalDequeueCount,Messages,"
082                            + "TotalMessageCount,ConsumerCount,TotalConsumerCount,DispatchCount,Duplex,NetworkTTL,Uptime");
083    
084            // Call the query command
085            super.parseOptions(queryTokens);
086            super.runTask(queryTokens);
087        }
088    
089        /**
090         * Print the help messages for the browse command
091         */
092        @Override
093        protected void printHelp() {
094            context.printHelp(helpFile);
095        }
096    
097    }