We'll start with calculated items that require typing in a formula. We're already monitoring total and used disk space. If we additionally wanted to monitor free disk space, we could query the agent for this information. This is where calculated items come in: if the agent or device doesn't expose a specific view of the data, or if we would like to avoid querying monitored hosts, we can do the calculation from the already retrieved values.
To create a calculated item that would compute the free disk space, do the following:
- Navigate to Configuration | Hosts, click on Items next to A test host, and then click on Create item. Fill in the following information:
-
- Name: Diskspace on / (free)
- Type: Calculated
- Key: calc.vfs.fs.size[/,free]
- Formula: last("vfs.fs.size[/,total]")-last("vfs.fs.size[/,used]")
- Units: B
- Update interval: 1800s
- When done, click on the Add button at the bottom.
All of the referenced items must exist. We can't enter keys here and have them gather data by extension from the calculated item. Values to compute the calculated item are retrieved from the Zabbix server caches or the database; no connections are made to the monitored devices.
With this item added, let's go to the Latest data page. As the interval was set to 1,800 seconds, we might have to wait a bit longer to see the value, but eventually it should appear:
The interval we used (1,800 seconds) wasn't matched to the intervals of both referenced items. Total and used disk space items were collecting data every 3,600 seconds, but calculated items aren't connected to the data collection of the referenced items in any way. A calculated item isn't evaluated when the referenced items get values; it follows its own scheduling, which is completely independent from the schedules of the referenced items and is semi-random. If the referenced items stopped collecting data, our calculated item would keep on using the latest value for the calculation, as we used the last() function. If one of them stopped collecting data, we would base our calculation on one recent and one outdated value. And if our calculated item could get very incorrect results if called at the wrong time, because one of the referenced items has significantly changed but the other hasn't received a new value yet, there's no easy solution to that, unfortunately. The custom scheduling discussed in Chapter 3, Monitoring with Zabbix Agents and Basic Protocols, could help here, but it could also introduce performance issues by polling values in uneven batches, and it would also be more complicated to manage. It's suggested to be used only as an exception.
We might also want to compute the total of incoming and outgoing traffic on an interface, and a calculated item would work well here. The formula would be like this:
last(net.if.in[enp0s8])+last(net.if.out[enp0s8])
Did you spot how we quoted item keys in the first example, but not here? The reason is that calculated item formula entries follow a syntax of function(key,function_parameter_1, function_parameter_2...). The item keys we referenced for the disk space item had commas in them like this: vfs.fs.size[/,total]. If we didn't quote the keys, Zabbix would interpret them as being vfs.fs.size[/ with a function parameter of total]. That wouldn't work.