Referencing items from multiple hosts

The calculated items we've created so far referenced items on a single host or template. We just supplied item keys to the functions. We may also reference items from multiple hosts in a calculated item; in that case, the formula syntax changes slightly. The only thing we have to do is prefix the item key with the hostname, separated by a colon, the same as in the trigger expressions:

function(host:item_key) 

Let's configure an item that would compute the average CPU load on both of our hosts:

  1. Navigate to Configuration | Hosts, click on Items next to A test host, and click on Create item. Fill in the following:
    • Name: Average system load for both servers
    • Type: Calculated
    • Key: calc.system.cpu.load.avg
    • Formula: (last(A test host:system.cpu.load)+last(Another host:system.cpu.load))/2
    • Type of information: Numeric (float)
  1. When done, click on the Add button at the bottom.

For triggers, when we referenced items, those triggers were associated with the hosts that the items came from. Calculated items also reference items, but they're always created on a single, specific host. The item we created will reside on A test host only. This means that such an item could also reside on a host that isn't included in the formulafor example, some calculations across a cluster could be done on a meta-host that holds cluster-wide items but isn't directly monitored itself.

Let's see whether this item works in Monitoring | Latest data. Make sure both of our hosts are shown and expand all entries. Look for three values, CPU Load both for A test host and Another host, as well as Average system load for both servers:

You can filter by load in the item names to see only relevant entries.

The value seems to be properly calculated. It could now be used like any normal item, maybe by including it and individual CPU load items from both hosts in a single graph. If we look at the values, the system loads for individual hosts are 1.62, and 0, and the average is calculated as 0.81. Sometimes, it can be that this isn't an exact fit, even far away from the rounding. Why would we get such a difference? Data for both items that the calculated item depends on comes in at different intervals, and the calculated value is computed at a slightly different time—hence, while the value itself is correct, it might not match the exact average of values seen at any given time. Here, both CPU Load items had some values and the calculated average was correctly computed. 

When we make use of items in calculated items, we reference them from existing items so we need to be careful to copy the exact item over as is. That means parameters have to match with the original itemalso, quotes and macros if we used them in our original item.
We discuss a few additional aspects regarding calculated items in Chapter 11, Automating Configuration.

..................Content has been hidden....................

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