【问题标题】:Using wild cards in JMX key to get a list of queue attributes在 JMX 键中使用通配符获取队列属性列表
【发布时间】:2020-12-26 23:04:31
【问题描述】:

我正在使用 Zabbix 通过 JMX 监控 ActiveMQ Artemis。我想检索一个包含所有队列的消息计数的 JSON 对象 - 如果可能的话。

Here 是我对这个主题的主要理解来源:

我可以像这样获取所有队列的所有属性:

jmx.get[attributes,"org.apache.activemq.artemis:broker=*,component=addresses,address=*,subcomponent=queues,routing-type=*,queue=*"]

以下是数组中一些项目的示例:

{
    "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\""
}

但是,现在我正试图弄清楚如何仅过滤 MessageCount。我试过这两个,但它返回一个空数组:

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"]

[编辑]

这是我目前的解决方案。这是我正在使用的密钥的示例:

jmx.get[attributes,"org.apache.activemq.artemis:broker=*,component=addresses,address=*,subcomponent=queues,routing-type=*,queue=*"]

这将获取所有队列的所有 JMX 属性。然后在 Preprocessing 选项卡下添加一个 JSONPath 查询:

$.[?(@.name=='MessageCount')]

这仅过滤消息计数属性。然后我用一点javascript来制作一个字符串。

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;

这只是循环遍历数组,如果它发现按摩计数大于值(本例中为 5),它会将队列名称和计数附加到字符串中。如果没有找到大于 5 的队列,我将字符串设置为“clear”。

然后当我创建一个动作时,如果值不是“清除”,我会触发一条消息。

【问题讨论】:

  • 谢谢贾斯汀。我更新了我的问题并取得了更多进展。
  • 我用我当前的解决方案更新了我的问题。

标签: jmx zabbix activemq-artemis


【解决方案1】:

根据Zabbix documentation

使用jmx.get[] 进行发现时,可以在发现规则配置的自定义LLD macro 选项卡中单独定义低级发现宏,使用JSONPath 指向所需的值。

Documentation on JSONPath functionality 也可以从 Zabbix 获得。

您不能只将name=MessageCountattribute=MessageCount 添加到MBean 名称中,因为它们实际上并不是MBean 名称的一部分。 “MessageCount”是从 MBean 检索的 属性。因此,您需要以其他方式获取它(例如使用 JSONPath)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-10
    • 2011-11-17
    • 1970-01-01
    • 2018-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-03
    相关资源
    最近更新 更多