Github user pgfox commented on a diff in the pull request:
https://github.com/apache/activemq-artemis/pull/1506#discussion_r136872715
--- 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 --
@michaelandrepearce Thanks Mike. I will change it to "--field queueName
--operation EQUALS --value Test1" and filter on columns (the set returned). I
was originally going for very simple little options but that will be more
useful. I hope to get to that tomorrow.
---