5 Discovery of JMX objects

Overview

It is possible to discover all JMX MBeans or MBean attributes or to specify a pattern for the discovery of these objects.

It is mandatory to understand the difference between an Mbean and Mbean attributes for discovery rule configuration. An MBean is an object which can represent a device, an application, or any resource that needs to be managed.

For example, there is an Mbean which represents a web server. Its attributes are connection count, thread count, request timeout, http file cache, memory usage, etc. Expressing this thought in human comprehensive language we can define a coffee machine as an Mbean which has the following attributes to be monitored: water amount per cup, average consumption of water for a certain period of time, number of coffee beans required per cup, coffee beans and water refill time, etc.

Item key

In discovery rule configuration, select JMX agent in the Type field.

Two item keys are supported for JMX object discovery - jmx.discovery[] and jmx.get[]:

Item key
Return valueParametersComment
jmx.discovery[<discovery mode>,<object name>]
This item returns a JSON array with LLD macros describing MBean objects or their attributes.discovery mode - one of the following: attributes (retrieve JMX MBean attributes, default) or beans (retrieve JMX MBeans)
object name - object name pattern (see documentation) identifying the MBean names to be retrieved (empty by default, retrieving all registered beans)
Examples:
→ jmx.discovery - retrieve all JMX MBean attributes
→ jmx.discovery[beans] - retrieve all JMX MBeans
→ jmx.discovery[attributes,”:type=GarbageCollector,name=“] - retrieve all garbage collector attributes
→ jmx.discovery[beans,”:type=GarbageCollector,name=“] - retrieve all garbage collectors

There are some limitations to what MBean properties this item can return based on limited characters that are supported in macro name generation (supported characters can described by the following regular expression: A-Z0-9_.). So, for example, to discover MBean properties with a hyphenated word or non-ASCII characters, you need to use jmx.get[].

Supported since Zabbix Java gateway 3.4.
jmx.get[<discovery mode>,<object name>]
This item returns a JSON array with MBean objects or their attributes.

Compared to jmx.discovery[] it does not define LLD macros.
discovery mode - one of the following: attributes (retrieve JMX MBean attributes, default) or beans (retrieve JMX MBeans)
object name - object name pattern (see documentation) identifying the MBean names to be retrieved (empty by default, retrieving all registered beans)
When using this item, it is needed to define custom low-level discovery macros, pointing to values extracted from the returned JSON using JSONPath.

Supported since Zabbix Java gateway 4.4.

If no parameters are passed, all MBean attributes from JMX are requested. Not specifying parameters for JMX discovery or trying to receive all attributes for a wide range like *:type=*,name=* may lead to potential performance problems.

Using jmx.discovery

This item returns a JSON object with low-level discovery macros describing MBean objects or attributes. For example, in the discovery of MBean attributes (reformatted for clarity):

  1. [
  2. {
  3. "{#JMXVALUE}":"0",
  4. "{#JMXTYPE}":"java.lang.Long",
  5. "{#JMXOBJ}":"java.lang:type=GarbageCollector,name=PS Scavenge",
  6. "{#JMXDESC}":"java.lang:type=GarbageCollector,name=PS Scavenge,CollectionCount",
  7. "{#JMXATTR}":"CollectionCount"
  8. },
  9. {
  10. "{#JMXVALUE}":"0",
  11. "{#JMXTYPE}":"java.lang.Long",
  12. "{#JMXOBJ}":"java.lang:type=GarbageCollector,name=PS Scavenge",
  13. "{#JMXDESC}":"java.lang:type=GarbageCollector,name=PS Scavenge,CollectionTime",
  14. "{#JMXATTR}":"CollectionTime"
  15. },
  16. {
  17. "{#JMXVALUE}":"true",
  18. "{#JMXTYPE}":"java.lang.Boolean",
  19. "{#JMXOBJ}":"java.lang:type=GarbageCollector,name=PS Scavenge",
  20. "{#JMXDESC}":"java.lang:type=GarbageCollector,name=PS Scavenge,Valid",
  21. "{#JMXATTR}":"Valid"
  22. },
  23. {
  24. "{#JMXVALUE}":"PS Scavenge",
  25. "{#JMXTYPE}":"java.lang.String",
  26. "{#JMXOBJ}":"java.lang:type=GarbageCollector,name=PS Scavenge",
  27. "{#JMXDESC}":"java.lang:type=GarbageCollector,name=PS Scavenge,Name",
  28. "{#JMXATTR}":"Name"
  29. },
  30. {
  31. "{#JMXVALUE}":"java.lang:type=GarbageCollector,name=PS Scavenge",
  32. "{#JMXTYPE}":"javax.management.ObjectName",
  33. "{#JMXOBJ}":"java.lang:type=GarbageCollector,name=PS Scavenge",
  34. "{#JMXDESC}":"java.lang:type=GarbageCollector,name=PS Scavenge,ObjectName",
  35. "{#JMXATTR}":"ObjectName"
  36. }
  37. ]

In the discovery of MBeans (reformatted for clarity):

  1. [
  2. {
  3. "{#JMXDOMAIN}":"java.lang",
  4. "{#JMXTYPE}":"GarbageCollector",
  5. "{#JMXOBJ}":"java.lang:type=GarbageCollector,name=PS Scavenge",
  6. "{#JMXNAME}":"PS Scavenge"
  7. }
  8. ]
Supported macros

The following macros are supported for use in the discovery rule filter and prototypes of items, triggers and graphs:

MacroDescription
Discovery of MBean attributes
{#JMXVALUE}Attribute value.
{#JMXTYPE}Attribute type.
{#JMXOBJ}Object name.
{#JMXDESC}Object name including attribute name.
{#JMXATTR}Attribute name.
Discovery of MBeans
{#JMXDOMAIN}MBean domain. (Zabbix reserved name)
{#JMXOBJ}Object name. (Zabbix reserved name)
{#JMX<key property>}MBean properties (like {#JMXTYPE}, {#JMXNAME}) (see Limitations below).
Limitations

There are some limitations associated with the algorithm of creating LLD macro names from MBean property names:

  • attribute names are changed to uppercase

  • attribute names are ignored (no LLD macros are generated) if they consist of unsupported characters for LLD macro names. Supported characters can be described by the following regular expression: A-Z0-9_\.

  • if an attribute is called “obj” or “domain” they will be ignored because of the overlap with the values of the reserved Zabbix properties {#JMXOBJ} and {#JMXDOMAIN} (supported since Zabbix 3.4.3.)

Please consider this jmx.discovery (with “beans” mode) example. MBean has the following properties defined:

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

As a result of JMX discovery, the following LLD macros will be generated:

  • {#JMXDOMAIN} - Zabbix internal, describing the domain of MBean

  • {#JMXOBJ} - Zabbix internal, describing MBean object

  • {#JMXNAME} - created from “name” property

Ignored properties are:

  • тип : its name contains unsupported characters (non-ASCII)

  • attributes[] : its name contains unsupported characters (square brackets are not supported)

  • Name : it’s already defined (name=test)

  • domAin : it’s a Zabbix reserved name

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:

MBean1MBean2MBean3
MBean1Attribute1MBean2Attribute1MBean3Attribute1
MBean1Attribute2MBean2Attribute2MBean3Attribute2
MBean1Attribute3MBean2Attribute3MBean3Attribute3
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:

5 Discovery of JMX objects - 图1

Key used:

  1. 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:

5 Discovery of JMX objects - 图2

Keys used:

  1. jmx[{#JMXOBJ},CollectionCount]
  2. jmx[{#JMXOBJ},CollectionTime]
  3. jmx[{#JMXOBJ},Valid]

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

5 Discovery of JMX objects - 图3

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:

5 Discovery of JMX objects - 图4

Key used:

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

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

5 Discovery of JMX objects - 图5

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:

  1. [
  2. {
  3. "object": "com.example:type=Hello,data-src=data-base,ключ=значение",
  4. "domain": "com.example",
  5. "properties": {
  6. "data-src": "data-base",
  7. "ключ": "значение",
  8. "type": "Hello"
  9. }
  10. },
  11. {
  12. "object": "com.example:type=Atomic",
  13. "domain": "com.example",
  14. "properties": {
  15. "type": "Atomic"
  16. }
  17. }
  18. ]
Discovering MBean attributes

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

Response:

  1. [
  2. {
  3. "object": "com.example:type=*",
  4. "domain": "com.example",
  5. "properties": {
  6. "type": "Simple"
  7. }
  8. },
  9. {
  10. "object": "com.zabbix:type=yes,domain=zabbix.com,data-source=/dev/rand,ключ=значение,obj=true",
  11. "domain": "com.zabbix",
  12. "properties": {
  13. "type": "Hello",
  14. "domain": "com.example",
  15. "data-source": "/dev/rand",
  16. "ключ": "значение",
  17. "obj": true
  18. }
  19. }
  20. ]