这是原厂英文文档的翻译页面. 欢迎帮助我们 完善文档.
2022 Zabbix中国峰会
2022 Zabbix中国峰会

5 发现JMX对象

概述

这能够发现 全部JMX MBeans或MBean属性,或指定用于发现这些对象的模式。

必须了解发现规则配置的Mbean和Mbean属性之间的区别。 MBean是一个对象,可以表示设备,应用程序或需要管理的任何资源。例如一个代表web-server的Mbean。 它的属性是连接数,线程数,请求超时,http文件缓存,内存使用等。 用普通人的语言理解这个想法的话,我们可以将咖啡机定义为Mbean,它具有以下被监控的点:每杯水量,一段时间内的平均水消耗量,每杯所需的咖啡豆数量,咖啡豆和补水时间等。

键值

发现规则 配置中, 在类型区域选择 JMX agent

该键值为:

jmx.discovery[<discovery mode>,<object name>]
  • 发现模式 - 其中之一:属性(检索JMX MBean属性,默认值)或beans(检索JMX MBeans)
  • 对象名称 - 辨别要检索的MBean名称的对象名称模式(默认为空,检索所有已注册的beans)。

你可以参考 使用手册里的 ObjectName以获取指定对象名称模式的选项。

如果未传递任何参数,则意味着请求JMX中的所有MBean属性。

不指定JMX发现的参数或尝试接收范围广泛的所有属性 *:type=*,name=* 可能会导致潜在的性能问题。

此监控项从Zabbix Java gateway 3.4开始支持。

键值举例:

jmx.discovery  #检索所有JMX MBean属性
       jmx.discovery[beans]  #检索所有 JMX MBeans
       jmx.discovery[attributes,"*:type=GarbageCollector,name=*"]  #检索所有垃圾收集器属性
       jmx.discovery[beans,"*:type=GarbageCollector,name=*"]  #检索所有垃圾收集器

此监控项反馈一个JSON对象。例如,在发现MBean属性(为清楚起见重新格式化):

{
          "data":[
             {
                "{#JMXVALUE}":"0",
                "{#JMXTYPE}":"java.lang.Long",
                "{#JMXOBJ}":"java.lang:type=GarbageCollector,name=PS Scavenge",
                "{#JMXDESC}":"java.lang:type=GarbageCollector,name=PS Scavenge,CollectionCount",
                "{#JMXATTR}":"CollectionCount"
             },
             {
                "{#JMXVALUE}":"0",
                "{#JMXTYPE}":"java.lang.Long",
                "{#JMXOBJ}":"java.lang:type=GarbageCollector,name=PS Scavenge",
                "{#JMXDESC}":"java.lang:type=GarbageCollector,name=PS Scavenge,CollectionTime",
                "{#JMXATTR}":"CollectionTime"
             },
             {
                "{#JMXVALUE}":"true",
                "{#JMXTYPE}":"java.lang.Boolean",
                "{#JMXOBJ}":"java.lang:type=GarbageCollector,name=PS Scavenge",
                "{#JMXDESC}":"java.lang:type=GarbageCollector,name=PS Scavenge,Valid",
                "{#JMXATTR}":"Valid"
             },
             {
                "{#JMXVALUE}":"PS Scavenge",
                "{#JMXTYPE}":"java.lang.String",
                "{#JMXOBJ}":"java.lang:type=GarbageCollector,name=PS Scavenge",
                "{#JMXDESC}":"java.lang:type=GarbageCollector,name=PS Scavenge,Name",
                "{#JMXATTR}":"Name"
             },
             {
                "{#JMXVALUE}":"java.lang:type=GarbageCollector,name=PS Scavenge",
                "{#JMXTYPE}":"javax.management.ObjectName",
                "{#JMXOBJ}":"java.lang:type=GarbageCollector,name=PS Scavenge",
                "{#JMXDESC}":"java.lang:type=GarbageCollector,name=PS Scavenge,ObjectName",
                "{#JMXATTR}":"ObjectName"
             }
          ]
       }

在发现MBean属性(为清楚起见重新格式化):

{
          "data":[
             {  
                "{#JMXDOMAIN}":"java.lang",
                "{#JMXTYPE}":"GarbageCollector",
                "{#JMXOBJ}":"java.lang:type=GarbageCollector,name=PS Scavenge",
                "{#JMXNAME}":"PS Scavenge"
             }
          ]
       }

支持宏

以下宏支持在发现规则中的过滤器,监控项,触发器和图表的原型中的应用:

发现MBean属性
{#JMXVALUE} 属性值。
{#JMXTYPE} 属性类型。
{#JMXOBJ} 对象名称。
{#JMXDESC} 对象名称,包括属性名称。
{#JMXATTR} 属性名称。
发现MBeans
{#JMXDOMAIN} MBean domain. (Zabbix保留名称)
{#JMXOBJ} Object name. (Zabbix保留名称)
{#JMX<key property>} MBean properties (like {#JMXTYPE}, {#JMXNAME}). 定义由以下算法从MBean属性名创建的MBean属性名时需要注意的一些重要事项:

属性名大小写改为大写;
属性名大小写被忽略(不生成LLD宏),如果它包含不支持的字符。支持的字符可以用以下正则表达式来描述:"A-Z0-9_\.";
如果一个属性名被称为"obj"或"domain",它将被Zabbix属性{#JMXOBJ}和{#JMXDOMAIN}的值所替换(自Zabbix 3.4.3以来支持)。

请考虑 jmx.discovery (以 "beans" 模式) 的例子. MBean定义了以下属性:

name=test
       тип=Type
       attributes []=1,2,3
       Name=NameOfTheTest
       domAin=some

作为JMX发现的结果,将生成以下LLD宏:

  • {#JMXDOMAIN} - Zabbix内部,描述了MBean领域
  • {#JMXOBJ} - Zabbix内部,描述了MBean对象
  • {#JMXNAME} - 从 "name" 属性创建

忽略的属性是:

  • тип : 它的名字内包含无法识别的字母 (non-ASCII)
  • attributes[] : 它的名字内包含无法识别的字母 (不支持方括号)
  • Name : 它已经被定义了 (name=test)
  • domAin : 这是Zabbix的保留名称

让我们回顾两个使用Mbean创建LLD规则的实际示例。 要了解收集Mbeans的LLD规则与收集Mbean属性的LLD规则之间的区别,请查看下表:

MBean1 MBean2 MBean3
MBean1Attribute1 MBean2Attribute1 MBean3Attribute1
MBean1Attribute2 MBean2Attribute2 MBean3Attribute2
MBean1Attribute3 MBean2Attribute3 MBean3Attribute3

以LLD规则收集Mbeans

规则将会反馈三个对象: 该列的顶行: MBean1, MBean2, MBean3.

有关对象的更多信息,请参阅 支持宏 表格, 发现MBean 部分。

收集Mbeans(无属性)的发现规则配置如下所示:

discovery_rule_mbean_1.png

使用键值:

jmx.discovery[beans,"*:type=GarbageCollector,name=*"]

能发现所有没有属性的垃圾收集器。 由于垃圾收集器具有相同的属性集,我们可以通过以下方式在项原型中使用所需的属性:

discovery_rule_mbean_2.png

使用键值:

jmx[{#JMXOBJ},CollectionCount] 
       jmx[{#JMXOBJ},CollectionTime] 
       jmx[{#JMXOBJ},Valid] 

LLD发现规则将导致与此接近的内容(为两个垃圾收集器发现的监控项):

discovery_rule_mbean_3.png

LLD规则收集MBean属性

这条规则将会反馈9个对象:MBean1Attribute1, MBean2Attribute1, Mbean3Attribute1,MBean1Attribute2,MBean2Attribute2, Mbean3Attribute2, MBean1Attribute3, MBean2Attribute3, Mbean3Attribute3.

更多有关于对象的信息,请参考 支持宏 表格, 发现MBean属性 部分.

收集MBean属性的发现规则配置如以下所示:

discovery_rule_mbean_attributes_1.png

使用键值:

jmx.discovery[attributes,"*:type=GarbageCollector,name=*"]

将发现具有单个项属性的所有垃圾收集器。

discovery_rule_mbean_attributes_2.png

在这种特殊情况下,将从原型为每个MBean属性创建一个监控项。这种配置的主要缺点是从触发器原型的触发器创建是不可能的,因为所有属性只有一个监控项原型。因此,此设置可用于数据收集,但不建议用于自动监控。

Examples

Let’s review two more practical examples of a LLD rule creation with the use of Mbean. To understand the difference between a LLD rule collecting Mbeans and a LLD rule collecting Mbean attributes better please take a look at following table:

MBean1 MBean2 MBean3
MBean1Attribute1 MBean2Attribute1 MBean3Attribute1
MBean1Attribute2 MBean2Attribute2 MBean3Attribute2
MBean1Attribute3 MBean2Attribute3 MBean3Attribute3
Example 1: Discovering Mbeans

This rule will return 3 objects: the top row of the column: MBean1, MBean2, MBean3.

For more information about objects please refer to supported macros table, Discovery of MBeans section.

Discovery rule configuration collecting Mbeans (without the attributes) looks like the following:

lld_rule_mbean0.png

Key used:

jmx.discovery[beans,"*:type=GarbageCollector,name=*"]

All the garbage collectors without attributes will be discovered. As Garbage collectors have the same attribute set, we can use desired attributes in item prototypes the following way:

discovery_rule_mbean_2.png

Keys used:

jmx[{#JMXOBJ},CollectionCount] 
       jmx[{#JMXOBJ},CollectionTime] 
       jmx[{#JMXOBJ},Valid] 

LLD discovery rule will result in something close to this (items are discovered for two Garbage collectors):

discovery_rule_mbean_3.png

Example 2: Discovering Mbean attributes

This rule will return 9 objects with the following fields: MBean1Attribute1, MBean2Attribute1, Mbean3Attribute1,MBean1Attribute2,MBean2Attribute2, Mbean3Attribute2, MBean1Attribute3, MBean2Attribute3, Mbean3Attribute3.

For more information about objects please refer to supported macros table, Discovery of MBean attributes section.

Discovery rule configuration collecting Mbean attributes looks like the following:

lld_rule_mbean_attr.png

Key used:

jmx.discovery[attributes,"*:type=GarbageCollector,name=*"]

All the garbage collectors with a single item attribute will be discovered.

discovery_rule_mbean_attributes_2.png

In this particular case an item will be created from prototype for every MBean attribute. The main drawback of this configuration is that trigger creation from trigger prototypes is impossible as there is only one item prototype for all attributes. So this setup can be used for data collection, but is not recommended for automatic monitoring.

Using jmx.get

jmx.get[] is similar to the jmx.discovery[] item, but is does not turn Java object properties into low-level discovery macro names and therefore can return values without limitations that are associated with LLD macro name generation such as hyphens or non-ASCII characters.

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.

Discovering MBeans

Discovery item: jmx.get[beans,"com.example:type=*,*"]

Response:

[
           {
               "object": "com.example:type=Hello,data-src=data-base,ключ=значение",
               "domain": "com.example",
               "properties": {
                   "data-src": "data-base",
                   "ключ": "значение",
                   "type": "Hello"
               }
           },
           {
               "object": "com.example:type=Atomic",
               "domain": "com.example",
               "properties": {
                   "type": "Atomic"
               }
           }
       ]
Discovering MBean attributes

Discovery item: jmx.get[attributes,"com.example:type=*,*"]

Response:

[
           {
               "object": "com.example:type=*",
               "domain": "com.example",
               "properties": {
                   "type": "Simple"
               }
           },
           {
               "object": "com.zabbix:type=yes,domain=zabbix.com,data-source=/dev/rand,ключ=значение,obj=true",
               "domain": "com.zabbix",
               "properties": {
                   "type": "Hello",
                   "domain": "com.example",
                   "data-source": "/dev/rand",
                   "ключ": "значение",
                   "obj": true
               }
           }
       ]