[
https://issues.apache.org/jira/browse/ARTEMIS-1384?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16152859#comment-16152859
]
ASF GitHub Bot commented on ARTEMIS-1384:
-----------------------------------------
Github user michaelandrepearce commented on a diff in the pull request:
https://github.com/apache/activemq-artemis/pull/1506#discussion_r136861961
--- Diff:
artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/QueueStats.java
---
@@ -0,0 +1,195 @@
+/*
+ * 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.artemis.cli.commands;
+
+import io.airlift.airline.Command;
+import io.airlift.airline.Option;
+import org.apache.activemq.artemis.api.core.JsonUtil;
+import org.apache.activemq.artemis.api.core.client.ClientMessage;
+import org.apache.activemq.artemis.api.core.management.ManagementHelper;
+
+import javax.json.JsonArray;
+import javax.json.JsonObject;
+import java.util.HashMap;
+
+@Command(name = "qstat", description = "prints out basic stats associated
with queues. Output includes " + "CONSUMERS (number of consumers), " +
"MESSAGES (current message count on the queue, including scheduled, paged and
in-delivery messages), " + "ADDED (messages added to the queue), " +
"DELIVERING (messages broker is currently delivering to consumer(s)), " +
"ACKED (messages acknowledged from the consumer(s))."
+
+)
+public class QueueStats extends AbstractAction {
+
+ public static final String NAME_FIELD = "name";
+ public static final String ADDRESS_FIELD = "address";
+ public static final String CONSUMER_COUNT_FIELD = "consumerCount";
+ public static final String MESSAGE_COUNT_FIELD = "messageCount";
+ public static final String MESSAGES_ADDED_FIELD = "messagesAdded";
+ public static final String DELIVERING_COUNT_FIELD = "deliveringCount";
+ public static final String MESSAGES_ACKED_FIELD = "messagesAcked";
+
+ @Option(name = "--queueName", description = "display queue stats for
queue(s) with names containing this string, " + "omitting this option will
return stats for all queues (until maxRows are reached).")
+ private String queueName;
+
+ @Option(name = "--exactMatch", description = "display queue stats for
queue(s) with this exact name. " + "Default is false.")
+ private boolean exactMatch = false;
+
+ @Option(name = "--maxRows", description = "max number of queues
displayed. Default is 50")
+ private int maxRows = 50;
+
+ //easier for testing
+ public void setQueueName(String queueName) {
+ this.queueName = queueName;
+ }
+
+ public void setExactMatch(boolean exactMatch) {
+ this.exactMatch = exactMatch;
+ }
+
+ public void setMaxRows(int maxRows) {
+ this.maxRows = maxRows;
+ }
+
+ public void setUser(String user) {
+ this.user = user;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ @Override
+ public Object execute(ActionContext context) throws Exception {
+ super.execute(context);
+ String filter = createFilter(queueName, exactMatch);
+
+ if (verbose) {
+ context.out.println("queueName='" + queueName + "'");
+ context.out.println("maxRows='" + maxRows + "'");
+ context.out.println("exactMatch='" + exactMatch + "'");
+ context.out.println("filter='" + filter + "'");
+ }
+
+ printStats(context, filter, maxRows);
+ return null;
+ }
+
+ private void printStats(final ActionContext context, final String
filter, int maxRows) throws Exception {
+ performCoreManagement(new ManagementCallback<ClientMessage>() {
+ @Override
+ public void setUpInvocation(ClientMessage message) throws
Exception {
+ ManagementHelper.putOperationInvocation(message, "broker",
"listQueues", filter, 1, maxRows);
+ }
+
+ @Override
+ public void requestSuccessful(ClientMessage reply) throws
Exception {
+ final String result = (String)
ManagementHelper.getResult(reply, String.class);
+ printStats(result);
+ }
+
+ @Override
+ public void requestFailed(ClientMessage reply) throws Exception {
+ String errMsg = (String) ManagementHelper.getResult(reply,
String.class);
+ context.err.println("Failed to get Stats for Queues. Reason: "
+ errMsg);
+ }
+ });
+ }
+
+ private void printStats(String result) {
+ printHeadings();
+
+ //should not happen but...
+ if (result == null) {
+ if (verbose) {
+ context.out.println("printStats(): got NULL result string.");
+ }
+ }
+
+ JsonObject queuesAsJsonObject = JsonUtil.readJsonObject(result);
+ JsonArray array = (JsonArray) queuesAsJsonObject.get("data");
+
+ for (int i = 0; i < array.size(); i++) {
+ printQueueStats(array.getJsonObject(i));
+ }
+ }
+
+ private void printHeadings() {
+
+ StringBuilder stringBuilder = new
StringBuilder(106).append('|').append(paddingString(new StringBuilder("QUEUE
NAME "), 25)).append('|').append(paddingString(new StringBuilder("ADDRESS NAME
"), 25)).append('|').append(paddingString(new StringBuilder("CONSUMERS "),
10)).append('|').append(paddingString(new StringBuilder("MESSAGES "),
9)).append('|').append(paddingString(new StringBuilder("ADDED "),
9)).append('|').append(paddingString(new StringBuilder("DELIVERING "),
11)).append('|').append(paddingString(new StringBuilder("ACKED "),
9)).append('|');
--- End diff --
Should headers not be the fieldNames? This then ties in with my comment
about more generic filter support, to support ability to filter by any fieldName
> add a CLI command to display basic queue stats
> -----------------------------------------------
>
> Key: ARTEMIS-1384
> URL: https://issues.apache.org/jira/browse/ARTEMIS-1384
> Project: ActiveMQ Artemis
> Issue Type: Improvement
> Components: Broker
> Affects Versions: 2.3.0
> Reporter: Pat Fox
> Priority: Minor
>
> In activemq 5.x there is a command line tool (called dstat) that listed some
> basic stats for queues/topics on the broker (current message count, current
> number of consumers, number of enqueued messages, number of dequeued
> messages).
> This is very useful for troubleshooting as a quick way to check basic
> destination stats or capture information if other management tools are not
> available.
> It would be good to have a similar command in the Artemis CLI that listed
> minimal set of stats for each queue.
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)