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 /**
045 * Performs a predefiend query option
046 * @param tokens - command arguments
047 * @throws Exception
048 */
049 protected void runTask(List<String> tokens) throws Exception {
050 List<String> queryTokens = new ArrayList<String>();
051 // Find the first non-option token
052 String brokerName = "*";
053 for (Iterator i = tokens.iterator(); i.hasNext();) {
054 String token = (String)i.next();
055 if (!token.startsWith("-")) {
056 brokerName = token;
057 break;
058 } else {
059 // Re-insert options
060 queryTokens.add(token);
061 }
062 }
063
064 // Build the predefined option
065 queryTokens.add("--objname");
066 queryTokens.add("Type=*,BrokerName=" + brokerName);
067 queryTokens.add("-xQTopic=ActiveMQ.Advisory.*");
068 queryTokens.add("--vuew");
069 queryTokens.add("Type,BrokerName,Destination,ConnectorName,EnqueueCount,"
070 + "DequeueCount,TotalEnqueueCount,TotalDequeueCount,Messages,"
071 + "TotalMessages,ConsumerCount,TotalConsumerCount,DispatchQueueSize");
072
073 // Call the query command
074 super.runTask(queryTokens);
075 }
076
077 /**
078 * Print the help messages for the browse command
079 */
080 protected void printHelp() {
081 context.printHelp(helpFile);
082 }
083
084 }