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 " --version Display the version information.",
033 " -h,-?,--help Display the query broker help information.",
034 "",
035 "Examples:",
036 " activemq-admin bstat localhost",
037 " - Display a summary of statistics for the broker 'localhost'"
038 };
039
040 /**
041 * Performs a predefiend query option
042 * @param tokens - command arguments
043 * @throws Exception
044 */
045 protected void runTask(List<String> tokens) throws Exception {
046 List<String> queryTokens = new ArrayList<String>();
047 // Find the first non-option token
048 String brokerName = "*";
049 for (Iterator i = tokens.iterator(); i.hasNext();) {
050 String token = (String)i.next();
051 if (!token.startsWith("-")) {
052 brokerName = token;
053 break;
054 } else {
055 // Re-insert options
056 queryTokens.add(token);
057 }
058 }
059
060 // Build the predefined option
061 queryTokens.add("--objname");
062 queryTokens.add("Type=*,BrokerName=" + brokerName);
063 queryTokens.add("-xQTopic=ActiveMQ.Advisory.*");
064 queryTokens.add("--vuew");
065 queryTokens.add("Type,BrokerName,Destination,ConnectorName,EnqueueCount,"
066 + "DequeueCount,TotalEnqueueCount,TotalDequeueCount,Messages,"
067 + "TotalMessages,ConsumerCount,TotalConsumerCount,DispatchQueueSize");
068
069 // Call the query command
070 super.runTask(queryTokens);
071 }
072
073 }