As we saw in the What to monitor? section, it's not always easy to monitor JMX items. As an example, Java has different garbage collectors and they can even change during the lifetime of the application, as it is the developer who decides what garbage collector fits best. Here, low-level discovery (LLD) comes to the rescue. Instead of creating a template with all possible combinations and seeing unsupported items all over our machines, we just discover what is on our hosts.
Let's go to our host Zabbix Java gateway and discover all garbage collectors:
- Go to Configuration | Hosts
- Select Java from the Group selection box
- Click on Discovery behind the Zabbix Java gateway host
- Click on Create discovery rule in the upper-right corner
Let's create our global discovery rule by adding the following:
- Name: Global JMX Discovery Rule
- Type: JMX agent
- Key: jmx.discovery[beans,"java.lang:type=GarbageCollector,name=*"]
- Update interval: 300s
When ready, click the Add button:
Next, we have to create our discovery item as we only have our global discovery rule. As you can see, we added in the key to discover beans. We could have added attributes here as well.
This is the list of items we can select:
- Attributes (retrieve JMX MBean attributes, default)
- Beans (retrieve JMX MBeans)
Time to create our discovery item; let's go to Item prototype | Create item prototype. Add the following parameters in our item:
- Name: java.gc {#JMXOBJ}-CollectionCount
- Type: JMX agent
- Key: jmx[{#JMXOBJ},CollectionCount]
- Type of information: Numeric (unsigned)
- New application prototype: {#JMXDESC}
Give it some time, then go to Monitoring | Latest data and select Zabbix Java gateway in Host:
As you can see, we now have the latest data for the collection count for our garbage collectors configured on the machine. In our case, the MarkSweepCompact and Copy Garbage Collectors were detected.
Because we added the {#JMXDESC} macro in the new application prototype, we now have a new item in the latest data for every newly-detected JMX object visible like in the preceding screenshot.
Zabbix maintains a list of supported macros for JMX LLD with a perfect explanation of what every macro does. This information can be found at https://zabbix.com/documentation/4.0/manual/discovery/low_level_discovery/jmx#supported_macros.