I'm using Zabbix to monitor ActiveMQ Artemis via JMX. I'd like to retrieve a JSON object with the message count for all the queues - if that's possible.
Here is my main source of understanding on this subject:
I can get all the attributes for all the queues like this:
jmx.get[attributes,"org.apache.activemq.artemis:broker=*,component=addresses,address=*,subcomponent=queues,routing-type=*,queue=*"]
Here is an example of a few items from the array:
{
"name": "Name",
"description": "name of this queue",
"type": "java.lang.String",
"value": "MAO.SOF.User.Import.Queue",
"object": "org.apache.activemq.artemis:broker=\"0.0.0.0\",component=addresses,address=\"MAO.SOF.User.Import.Topic\",subcomponent=queues,routing-type=\"multicast\",queue=\"MAO.SOF.User.Import.Queue\""
},
{
"name": "Address",
"description": "address this queue is bound to",
"type": "java.lang.String",
"value": "MAO.SOF.User.Import.Topic",
"object": "org.apache.activemq.artemis:broker=\"0.0.0.0\",component=addresses,address=\"MAO.SOF.User.Import.Topic\",subcomponent=queues,routing-type=\"multicast\",queue=\"MAO.SOF.User.Import.Queue\""
},
{
"name": "MessageCount",
"description": "number of messages currently in this queue (includes scheduled, paged, and in-delivery messages)",
"type": "java.lang.Long",
"value": "0",
"object": "org.apache.activemq.artemis:broker=\"0.0.0.0\",component=addresses,address=\"MAO.SOF.User.Import.Topic\",subcomponent=queues,routing-type=\"multicast\",queue=\"MAO.SOF.User.Import.Queue\""
}
However, now I'm trying to figure out how to filter for only MessageCount
. I've tried these two, but it returns an empty array:
jmx.get[attributes,"org.apache.activemq.artemis:broker=*,component=addresses,address=*,subcomponent=queues,routing-type=*,queue=*,name=MessageCount"]
jmx.get[attributes,"org.apache.activemq.artemis:broker=*,component=addresses,address=*,subcomponent=queues,routing-type=*,queue=*,attribute=MessageCount"]
[Edit]
Here is my current solution for this. Here is an example of the key I'm using:
jmx.get[attributes,"org.apache.activemq.artemis:broker=*,component=addresses,address=*,subcomponent=queues,routing-type=*,queue=*"]
This gets all of the JMX properties for all of the queues. Then under the Preprocessing tab I add a JSONPath query:
$.[?(@.name=='MessageCount')]
This filters for only the message count property. Then I use a little javascript to make a string.
var object = JSON.parse(value);
var returnString = "";
for (var i=0; i<object.length; i++) {
if (object[i].value > 5) {
returnString = returnString + object[i].object.substring(object[i].object.lastIndexOf("\",queue=\"")+9, object[i].object.length-1) + " has " + object[i].value + " messages pending.\n";
}
}
if (returnString.length==0) {
returnString = "clear";
}
return returnString;
This simply loops through the array and if it finds a massage count greater than the value (5 in this example) it append the queue name and count to a string. If no queues were found with >5, I set the string to "clear".
Then when I create an action, I trigger a message if the value isn't "clear".
According to the Zabbix documentation:
When using
jmx.get[]
for discovery, low-level discovery macros can be defined separately in the custom LLD macro tab of the discovery rule configuration, using JSONPath to point to the required values.
Documentation on JSONPath functionality is available from Zabbix as well.
You can't just add name=MessageCount
or attribute=MessageCount
to the MBean name as those aren't actually a part of the MBean's name. "MessageCount" is an attribute retrieved from the MBean. Therefore you need to fetch it some other way (e.g. using JSONPath).