Skip to content

Reduce Polling with Dependent Items and JSONPath

Using Zabbix Dependent Items and JSONPath we can significantly reduce the number of times we hit an API when monitoring the metrics it makes available to us.

Most web API’s today use some sort of JSON-formatted data structure to deliver data. Dependent Items and JSONPath allow us to dig through that data with ease!

Excerpt from zabbix.com about Dependent Items:

To allow for bulk metric collection and simultaneous use in several related items, Zabbix supports dependent items. Dependent items depend on the master item that collects their data simultaneously, in one query. A new value for the master item automatically populates the values of the dependent items. Dependent items cannot have a different update interval than the master item.

Zabbix preprocessing options can be used to extract the part that is needed for the dependent item from the master item data.

Preprocessing is managed by a preprocessing manager process, which has been added in Zabbix 3.4, along with workers that perform the preprocessing steps. All values (with or without preprocessing) from different data gatherers pass through the preprocessing manager before being added to the history cache. Socket-based IPC communication is used between data gatherers (pollers, trappers, etc) and the preprocessing process.

Zabbix server or Zabbix proxy (if host is monitored by proxy) are performing preprocessing steps and processing dependent items.

Item of any type, even dependent item, can be set as master item. Additional levels of dependent items can be used to extract smaller parts from the value of an existing dependent item.

Grabbing Some Data

So, let’s say we’re polling a weather API and the API returns the following data:

{
  "temp_c": "28.0",
  "temp_f": "82.4",
  "humidity": "67.9"
}

By setting up 3 independent items, and configuring JSONPath preprocessing on each item, we’d be good to go! However for each item we’d be polling the API, getting all 3 metrics, discarding what we don’t need and only keeping the data relevant for that item. What a waste!

Dependent Items

We can instead set up a single “Master Item” that grabs the data from the API. Having done so, we can then setup additional items and refer them to the Master Item. When the Master Item is polled and updated, so are all the dependent items! Using JSONPath preprocessing on those additional items, we can parse out the information we need to each one of them. As an example, for the Dependent Item “Temperature in Celcius”, we’d then add a preprocessing step:

Like any other item, you can add additional preprocessing steps to them, should you want to.

We then repeat this for the ”temp_f” and “humidity” metrics as well. Now we’re polling all 3 metrics with a single API call instead of 3!

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.