# 7 Calculated items

#### Overview

With calculated items you can create calculations on the basis of other
items.

Thus, calculated items are a way of creating virtual data sources. The
values will be periodically calculated based on an arithmetical
expression. All calculations are done by the Zabbix server - nothing
related to calculated items is performed on Zabbix agents or proxies.

The resulting data will be stored in the Zabbix database as for any
other item - this means storing both history and trend values for fast
graph generation. Calculated items may be used in trigger expressions,
referenced by macros or other entities same as any other item type.
Comparison to strings is allowed in calculated items.

To use calculated items, choose the item type **Calculated**.

#### Configurable fields

The **key** is a unique item identifier (per host). You can create any
key name using supported symbols.

Calculation definition should be entered in the **Formula** field. There
is virtually no connection between the formula and the key. The key
parameters are not used in formula in any way.

The correct syntax of a simple formula is:

    func(<key>|<hostname:key>,<parameter1>,<parameter2>,...)

Where:

|ARGUMENT|DEFINITION|
|--------|----------|
|**func**|One of the [functions](/manual/appendix/triggers/functions) supported in trigger expressions: last, min, max, avg, count, etc|
|**key**|The key of another item whose data you want to use. It may be defined as **key** or **hostname:key**.<br>*Note:* Putting the whole key in double quotes ("...") is strongly recommended to avoid incorrect parsing because of spaces or commas within the key.<br>If there are also quoted parameters within the key, those double quotes must be escaped by using the backslash (\\). See **Example 5** below.|
|**parameter(s)**|Function parameter(s), if required.|

::: notetip
All items that are referenced from the calculated item
formula must exist and be collecting data (exceptions in [functions and
unsupported
items](/manual/appendix/triggers/functions#functions_and_unsupported_items)).
Also, if you change the item key of a referenced item, you have to
manually update any formulas using that key.
:::

::: noteimportant
[User macros](/manual/config/macros/user_macros)
in the formula will be expanded if used to reference a function
parameter or a constant. User macros will NOT be expanded if referencing
a function, host name, item key, item key parameter or
operator.
:::

A more complex formula may use a combination of functions, operators and
brackets. You can use all functions and
[operators](/manual/config/triggers/expression#operators) supported in
trigger expressions. Note that the syntax is slightly different, however
logic and operator precedence are exactly the same.

Unlike trigger expressions, Zabbix processes calculated items according
to the item update interval, not upon receiving a new value.

::: noteclassic
If the calculation result is a float value it will be
trimmed to an integer if the calculated item type of information is
*Numeric (unsigned)*.
:::

A calculated item may become unsupported in several cases:

1.  referenced item(s)
    -   is not found
    -   is disabled
    -   belongs to a disabled host
    -   is not supported (see exceptions in [functions and unsupported
        items](/manual/appendix/triggers/functions#functions_and_unsupported_items),
        [Expressions with unsupported items and unknown
        values](/manual/config/triggers/expression#expressions_with_unsupported_items_and_unknown_values)
        and [Operators](/manual/config/triggers/expression#operators))
2.  no data to calculate a function
3.  division by zero
4.  incorrect syntax used

Support for calculated items was introduced in Zabbix 1.8.1.<br>
Starting from Zabbix 3.2 calculated items in some cases may involve
unsupported items as described in [functions and unsupported
items](/manual/appendix/triggers/functions#functions_and_unsupported_items),
[Expressions with unsupported items and unknown
values](/manual/config/triggers/expression#expressions_with_unsupported_items_and_unknown_values)
and [Operators](/manual/config/triggers/expression#operators).

#### Usage examples

##### Example 1

Calculating percentage of free disk space on '/'.

Use of function **last**:

    100*last("vfs.fs.size[/,free]")/last("vfs.fs.size[/,total]")

Zabbix will take the latest values for free and total disk spaces and
calculate percentage according to the given formula.

##### Example 2

Calculating a 10-minute average of the number of values processed by
Zabbix.

Use of function **avg**:

    avg("Zabbix Server:zabbix[wcache,values]",600)

Note that extensive use of calculated items with long time periods may
affect performance of Zabbix server.

##### Example 3

Calculating total bandwidth on eth0.

Sum of two functions:

    last("net.if.in[eth0,bytes]")+last("net.if.out[eth0,bytes]")

##### Example 4

Calculating percentage of incoming traffic.

More complex expression:

    100*last("net.if.in[eth0,bytes]")/(last("net.if.in[eth0,bytes]")+last("net.if.out[eth0,bytes]"))

##### Example 5

Using aggregated items correctly within a calculated item.

Take note of how double quotes are escaped within the quoted key:

    last("grpsum[\"video\",\"net.if.out[eth0,bytes]\",\"last\"]") / last("grpsum[\"video\",\"nginx_stat.sh[active]\",\"last\"]") 
