Beginning in ActiveMQ 5.3, a statistics plugin is included that can be used to retrieve statistics from the broker or its destinations. Note that the message must contain a To retrieve stats for the broker, just send an empty message to the destination named To configure ActiveMQ to use the statistics plugin, just add the following to the ActiveMQ XML configuration: <broker ...> <plugins> <statisticsBrokerPlugin/> </plugins> </broker> The statistics plugin looks for messages sent to particular destinations. Below is an example of using the statistics plugin to grab stats from a broker: Queue replyTo = session.createTemporaryQueue(); MessageConsumer consumer = session.createConsumer(replyTo); String queueName = "ActiveMQ.Statistics.Broker"; Queue testQueue = session.createQueue(queueName); MessageProducer producer = session.createProducer(testQueue); Message msg = session.createMessage(); msg.setJMSReplyTo(replyTo); producer.send(msg); MapMessage reply = (MapMessage) consumer.receive(); assertNotNull(reply); for (Enumeration e = reply.getMapNames();e.hasMoreElements();) { String name = e.nextElement().toString(); System.out.println(name + "=" + reply.getObject(name)); } The output from the code above is shown below: vm=vm://localhost Similarly, to query the statistics for a destination just send a message to the destination name prepended with Queue replyTo = session.createTemporaryQueue(); MessageConsumer consumer = session.createConsumer(replyTo); Queue testQueue = session.createQueue("TEST.FOO"); MessageProducer producer = session.createProducer(null); String queueName = "ActiveMQ.Statistics.Destination." + testQueue.getQueueName() Queue query = session.createQueue(queueName); Message msg = session.createMessage(); producer.send(testQueue, msg) msg.setJMSReplyTo(replyTo); producer.send(query, msg); MapMessage reply = (MapMessage) consumer.receive(); assertNotNull(reply); assertTrue(reply.getMapNames().hasMoreElements()); for (Enumeration e = reply.getMapNames();e.hasMoreElements();) { String name = e.nextElement().toString(); System.err.println(name + "=" + reply.getObject(name)); } The output from the code above is shown below: memoryUsage=0 You can also use wildcards in the queue name, too. This will result in a separate stats message for every destination that is matched by the wildcard. Very handy indeed. Subscriptions statisticsSince 5.6.0 you can also retrieve statistics on all queue and topic subscriptions. All you need to do it send an empty message to the destination named Below is an example of using the statistics plugin to grab stats from a broker: Queue replyTo = session.createTemporaryQueue(); MessageConsumer consumer = session.createConsumer(replyTo); String queueName = "ActiveMQ.Statistics.Subscription"; Queue testQueue = session.createQueue(queueName); MessageProducer producer = session.createProducer(testQueue); Message msg = session.createMessage(); msg.setJMSReplyTo(replyTo); producer.send(msg); MapMessage reply = (MapMessage) consumer.receive(); assertNotNull(reply); for (Enumeration e = reply.getMapNames();e.hasMoreElements();) { String name = e.nextElement().toString(); System.out.println(name + "=" + reply.getObject(name)); } An example output from the code above is shown below: selector=null |