Calculated items

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:

  1. 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
  1. When done, click on the Add button at the bottom.
We chose a key that wouldn't clash with the native key in case somebody decides to use that later, but we're free to use any key for calculated items.

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:

If the item turns unsupported, check the error message and make sure the formula you typed in is correct.

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.

The free disk space that we calculated might not match the available disk space reported by system tools. Many filesystems and operating systems reserve some space that doesn't count as used, but counts against the available disk space.

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]) 
There's no need anymore to calculate total traffic on an interface in Zabbix 4.0 as there's now an item that can do this for us. We can make use of net.if.total[<paramenters>] now.
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.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.72.224