Working with calculated and dependent items
Calculated and dependent items are used in Zabbix to produce additional values from existing values. Sometimes, we have already collected a value and we need to do more with the values created by that item. We can do exactly that by using calculated and dependent items.
Getting ready
To work with calculated items and dependent items, we are going to need the Zabbix server and monitored hosts from the previous recipes. We will add the items on the lar-book-agent_passive host and our Zabbix server host, so we already have some items available to calculate and make dependent.
How to do it…
Let's see how we can extend our items by getting started with the calculated items.
Working with calculated items
- Let's navigate to our host configuration by going to Configuration | Hosts and clicking on our lar-book-agent_passive host's items. In the filter field named Name, enter
memory
and you will get the following output: - What we are going to do now is create a calculated item that is going to show us the average memory utilization over a period of 15 minutes. We can use this value to determine how busy our host was during that period, without having to look at the graphs.
- Let's click the Create item button and start creating our new calculated item.
We want our item to have the following values:
- Now if we go to check our Monitoring | Hosts page and select Latest data, we can check out our value. Make sure to filter in the Name field for
memory
, so we see the correct values:
Now we can clearly see that we are calculating the 15-minute average of the memory utilization on our newly created item.
Working with dependent items
Time to make our first dependent item. I'll use the lar-book-agent_centos host or our (as it's called by default) Zabbix server. Let's say we want to request some variables from our MySQL database in one big batch. We can then create dependent items on top of the first item to further process the data:
- Let's start by creating the main check. Navigate to Configuration | Hosts, select our host, and then let's click the Create item button to start creating our first new item. We want an item with the following variables:
Now, this item is an SSH check that logs in to our Zabbix server machine and executes the code in the script. The code will then log in to our MariaDB database and it will show the status. Make sure to enter your credentials correctly.
Tip
SSH checks can be used for a variety of cool scenarios, such as this one. We simply log in to our CLI and execute a piece of code. Perfect for your custom setups.
- Go to Monitoring | Hosts and check out the Latest data page for our new check. There should be a long list of MariaDB values. If so, we can continue with our next step of creating the dependent item.
- To create the dependent item, navigate to Configuration | Hosts, select our host, and let's click the Create item button. We want this item to get the following variables:
- It's very important to add preprocessing to this item as well, otherwise we will simply get the same data as our master item. So, let's add the following:
The result will be the number of aborted clients for our MariaDB:
How it works…
The types we've discussed in this How to do it… section can be quite complicated; let's go over how the items actually work.
Calculated items
Working with calculated items can be a great way to get even more statistics out of your existing data. Sometimes you just need to combine multiple items into one specific value.
What we did just now works by taking several values in a period of 15 minutes of 1 item and calculating the average like this:
We're taking those values and calculating the average every 15 minutes. It gives us a nice indication of what we are doing over a set period of time.
Dependent items
Dependent items work simply by taking the data from a master item and processing that data into other data. This way, we can structure our data and keep our check interval for all these items the same:
As seen here, dependent items basically work as duplicators, with additional preprocessing options. Do note that preprocessing must be used to extract data from the master item. Without preprocessing, our data will be exactly the same as the master item.
Tip
Sometimes we do not require our master item to be saved in our database; we already have the information in our dependent items. When we don't want the master item to be saved, we simply select the Do not keep history option.