mirror of https://github.com/apache/activemq.git
Adds dstat command git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1518321 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f4d51e092b
commit
3c776cfc44
|
@ -0,0 +1,176 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.console.command;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.management.MBeanServerInvocationHandler;
|
||||
import javax.management.ObjectInstance;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
import org.apache.activemq.broker.jmx.QueueViewMBean;
|
||||
import org.apache.activemq.broker.jmx.TopicViewMBean;
|
||||
import org.apache.activemq.console.util.JmxMBeansUtil;
|
||||
|
||||
public class DstatCommand extends AbstractJmxCommand {
|
||||
|
||||
private static final String queryString =
|
||||
"type=Broker,brokerName=*,destinationType=%1,destinationName=*,*";
|
||||
|
||||
protected String[] helpFile = new String[] {
|
||||
"Task Usage: activemq-admin dstat [dstat-options] [destination-type]",
|
||||
"Description: Performs a predefined query that displays useful statistics regarding the specified .",
|
||||
" destination type (Queues or Topics) and displays those results in a tabular format.",
|
||||
" If no broker name is specified, it will try and select from all registered brokers.",
|
||||
"",
|
||||
"dstat Options:",
|
||||
" --jmxurl <url> Set the JMX URL to connect to.",
|
||||
" --pid <pid> Set the pid to connect to (only on Sun JVM).",
|
||||
" --jmxuser <user> Set the JMX user used for authenticating.",
|
||||
" --jmxpassword <password> Set the JMX password used for authenticating.",
|
||||
" --jmxlocal Use the local JMX server instead of a remote one.",
|
||||
" --version Display the version information.",
|
||||
" -h,-?,--help Display the query broker help information.",
|
||||
"",
|
||||
"Examples:",
|
||||
" activemq-admin dstat queues",
|
||||
" - Display a tabular summary of statistics for the queues on the broker.",
|
||||
" activemq-admin dstat topics",
|
||||
" - Display a tabular summary of statistics for the queues on the broker."
|
||||
};
|
||||
|
||||
/**
|
||||
* Execute the dstat command, which allows you to display information for topics or queue in
|
||||
* a tabular format.
|
||||
*
|
||||
* @param tokens - command arguments
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
protected void runTask(List<String> tokens) throws Exception {
|
||||
try {
|
||||
|
||||
if (tokens.contains("topics")) {
|
||||
displayTopicStats();
|
||||
} else if (tokens.contains("queues")) {
|
||||
displayQueueStats();
|
||||
} else {
|
||||
displayAllDestinations();
|
||||
}
|
||||
|
||||
// Iterate through the queue names
|
||||
} catch (Exception e) {
|
||||
context.printException(new RuntimeException("Failed to execute dstat task. Reason: " + e));
|
||||
throw new Exception(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void displayAllDestinations() throws IOException, Exception {
|
||||
|
||||
String query = JmxMBeansUtil.createQueryString(queryString, "*");
|
||||
List<?> queueList = JmxMBeansUtil.queryMBeans(createJmxConnection(), query);
|
||||
|
||||
final String header = "%20s %10s %10s %10s %10s";
|
||||
final String tableRow = "%20s %10d %10d %10d %10d";
|
||||
|
||||
context.print(String.format(Locale.US, header, "Name", "Pending", "Consumers", "Enqueued", "Dequeued"));
|
||||
|
||||
// Iterate through the queue result
|
||||
for (Object view : queueList) {
|
||||
ObjectName queueName = ((ObjectInstance)view).getObjectName();
|
||||
QueueViewMBean queueView = MBeanServerInvocationHandler.
|
||||
newProxyInstance(createJmxConnection(), queueName, QueueViewMBean.class, true);
|
||||
|
||||
context.print(String.format(Locale.US, tableRow,
|
||||
queueView.getName(),
|
||||
queueView.getQueueSize(),
|
||||
queueView.getConsumerCount(),
|
||||
queueView.getEnqueueCount(),
|
||||
queueView.getDequeueCount()));
|
||||
}
|
||||
}
|
||||
|
||||
private void displayQueueStats() throws IOException, Exception {
|
||||
|
||||
String query = JmxMBeansUtil.createQueryString(queryString, "Queue");
|
||||
List<?> queueList = JmxMBeansUtil.queryMBeans(createJmxConnection(), query);
|
||||
|
||||
final String header = "%20s %10s %10s %10s %10s";
|
||||
final String tableRow = "%20s %10d %10d %10d %10d";
|
||||
|
||||
context.print(String.format(Locale.US, header, "Name", "Pending", "Consumers", "Enqueued", "Dequeued"));
|
||||
|
||||
// Iterate through the queue result
|
||||
for (Object view : queueList) {
|
||||
ObjectName queueName = ((ObjectInstance)view).getObjectName();
|
||||
QueueViewMBean queueView = MBeanServerInvocationHandler.
|
||||
newProxyInstance(createJmxConnection(), queueName, QueueViewMBean.class, true);
|
||||
|
||||
context.print(String.format(Locale.US, tableRow,
|
||||
queueView.getName(),
|
||||
queueView.getQueueSize(),
|
||||
queueView.getConsumerCount(),
|
||||
queueView.getEnqueueCount(),
|
||||
queueView.getDequeueCount()));
|
||||
}
|
||||
}
|
||||
|
||||
private void displayTopicStats() throws IOException, Exception {
|
||||
|
||||
String query = JmxMBeansUtil.createQueryString(queryString, "Topic");
|
||||
List<?> topicsList = JmxMBeansUtil.queryMBeans(createJmxConnection(), query);
|
||||
|
||||
final String header = "%20s %10s %10s %10s";
|
||||
final String tableRow = "%20s %10d %10d %10d";
|
||||
|
||||
context.print(String.format(Locale.US, header, "Name", "Consumers", "Enqueued", "Dequeued"));
|
||||
|
||||
// Iterate through the topics result
|
||||
for (Object view : topicsList) {
|
||||
ObjectName topicName = ((ObjectInstance)view).getObjectName();
|
||||
TopicViewMBean topicView = MBeanServerInvocationHandler.
|
||||
newProxyInstance(createJmxConnection(), topicName, TopicViewMBean.class, true);
|
||||
|
||||
context.print(String.format(Locale.US, tableRow,
|
||||
topicView.getName(),
|
||||
topicView.getConsumerCount(),
|
||||
topicView.getEnqueueCount(),
|
||||
topicView.getDequeueCount()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "dstat";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOneLineDescription() {
|
||||
return "Performs a predefined query that displays useful tabular statistics regarding the specified destination type";
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the help messages for this command
|
||||
*/
|
||||
@Override
|
||||
protected void printHelp() {
|
||||
context.printHelp(helpFile);
|
||||
}
|
||||
|
||||
}
|
|
@ -21,6 +21,7 @@ org.apache.activemq.console.command.ListCommand
|
|||
org.apache.activemq.console.command.AmqBrowseCommand
|
||||
org.apache.activemq.console.command.QueryCommand
|
||||
org.apache.activemq.console.command.BstatCommand
|
||||
org.apache.activemq.console.command.DstatCommand
|
||||
org.apache.activemq.console.command.EncryptCommand
|
||||
org.apache.activemq.console.command.DecryptCommand
|
||||
org.apache.activemq.console.command.StoreExportCommand
|
||||
|
|
Loading…
Reference in New Issue