6.6. Using message counters
You use message counters to obtain information about queues over time. This helps you to identify trends that would otherwise be difficult to see.
For example, you could use message counters to determine how a particular queue is being used over time. You could also attempt to obtain this information by using the management API to query the number of messages in the queue at regular intervals, but this would not show how the queue is actually being used. The number of messages in a queue can remain constant because no clients are sending or receiving messages on it, or because the number of messages sent to the queue is equal to the number of messages consumed from it. In both of these cases, the number of messages in the queue remains the same even though it is being used in very different ways.
6.6.1. Types of message counters 링크 복사링크가 클립보드에 복사되었습니다!
Message counters provide additional information about queues on a broker.
count- The total number of messages added to the queue since the broker was started.
countDelta- The number of messages added to the queue since the last message counter update.
lastAckTimestamp- The time stamp of the last time a message from the queue was acknowledged.
lastAddTimestamp- The time stamp of the last time a message was added to the queue.
messageCount- The current number of messages in the queue.
messageCountDelta-
The overall number of messages added/removed from the queue since the last message counter update. For example, if
messageCountDeltais-10, then 10 messages overall have been removed from the queue. udpateTimestamp- The time stamp of the last message counter update.
You can combine message counters to determine other meaningful data as well. For example, to know specifically how many messages were consumed from the queue since the last update, you would subtract the messageCountDelta from countDelta.
6.6.2. Enabling message counters 링크 복사링크가 클립보드에 복사되었습니다!
Message counters can have a small impact on the broker’s memory; therefore, they are disabled by default. To use message counters, you must first enable them.
Procedure
-
Open the
<broker_instance_dir>/etc/broker.xmlconfiguration file. Enable message counters.
<message-counter-enabled>true</message-counter-enabled>Set the message counter history and sampling period.
<message-counter-max-day-history>7</message-counter-max-day-history> <message-counter-sample-period>60000</message-counter-sample-period>message-counter-max-day-history- The number of days the broker should store queue metrics. The default is 10 days.
message-counter-sample-period- How often (in milliseconds) the broker should sample its queues to collect metrics. The default is 10000 milliseconds.
6.6.3. Retrieving message counters 링크 복사링크가 클립보드에 복사되었습니다!
You can use the management API to retrieve message counters.
Prerequisites
Message counters must be enabled on the broker.
For more information, see 6.6.2절. “Enabling message counters”.
Procedure
Use the management API to retrieve message counters.
// Retrieve a connection to the broker's MBeanServer. MBeanServerConnection mbsc = ... JMSQueueControlMBean queueControl = (JMSQueueControl)MBeanServerInvocationHandler.newProxyInstance(mbsc, on, JMSQueueControl.class, false); // Message counters are retrieved as a JSON string. String counters = queueControl.listMessageCounter(); // Use the MessageCounterInfo helper class to manipulate message counters more easily. MessageCounterInfo messageCounter = MessageCounterInfo.fromJSON(counters); System.out.format("%s message(s) in the queue (since last sample: %s)\n", messageCounter.getMessageCount(), messageCounter.getMessageCountDelta());
Additional resources
- For more information about message counters, see 6.4.3절. “Queue management operations”.