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