[comment]: # translation:outdated

[comment]: # ({bfe1a94d-bfe1a94d})
# Aggregate calculations

[comment]: # ({/bfe1a94d-bfe1a94d})

[comment]: # ({f8e62abe-f8e62abe})
#### Overview

In aggregate [calculations](/manual/config/items/itemtypes/calculated)
information from several items may be collected by Zabbix server (by
doing direct database queries) to calculate an aggregate, depending on
the aggregate function used.

Aggregate calculations do not require any agent running on the host
being monitored.

To define aggregate calculations, select the **Calculated** item type.

[comment]: # ({/f8e62abe-f8e62abe})

[comment]: # ({new-7b7f2f76})
#### Syntax

Aggregates can be retrieved by working with either:

-   history of items:

```{=html}
<!-- -->
```
    aggregate_function(function(/host/item,parameter),function(/host2/item2,parameter),...)

-   a [foreach function](/manual/appendix/functions/aggregate/foreach)
    as the only parameter:

```{=html}
<!-- -->
```
    aggregate_function(foreach_function(/*/key?[group="host group"],timeperiod))

where:

      * ''aggregate_function'' is one of the supported [[:manual:appendix:functions:aggregate|aggregate functions]]: avg, max, min, sum, etc.
      * ''foreach_function'' is one of the supported foreach functions: avg_foreach, count_foreach, etc. 

Foreach functions work with the history of multiple items and return an
array of values - one for each item.

::: noteclassic
If the aggregate results in a float value it will be trimmed
to an integer if the aggregated item type of information is *Numeric
(unsigned)*.
:::

An aggregate calculation may become unsupported if:

-   none of the referenced items is found (which may happen if the item
    key is incorrect, none of the items exists or all included groups
    are incorrect)
-   no data to calculate a function

[comment]: # ({/new-7b7f2f76})

[comment]: # ({3bbe172c-3bbe172c})
#### Usage examples

Examples of keys for aggregate calculations.

[comment]: # ({/3bbe172c-3bbe172c})

[comment]: # ({874bcf94-874bcf94})
##### Example 1

Total disk space of host group 'MySQL Servers'.

    sum(last_foreach(/*/vfs.fs.size[/,total]?[group="MySQL Servers"]))

[comment]: # ({/874bcf94-874bcf94})

[comment]: # ({3182672a-3182672a})
##### Example 2

Sum of latest values of all items matching net.if.in\[\*\] on the host.

    sum(last_foreach(/host/net.if.in[*]))

[comment]: # ({/3182672a-3182672a})

[comment]: # ({cdf2da8b-cdf2da8b})
##### Example 3

Average processor load of host group 'MySQL Servers'.

    avg(last_foreach(/*/system.cpu.load[,avg1]?[group="MySQL Servers"]))

[comment]: # ({/cdf2da8b-cdf2da8b})

[comment]: # ({db9c8fce-db9c8fce})
##### Example 4

5-minute average of the number of queries per second for host group
'MySQL Servers'.

    avg(avg_foreach(/*/mysql.qps?[group="MySQL Servers"],5m))

[comment]: # ({/db9c8fce-db9c8fce})

[comment]: # ({0233edd3-0233edd3})
##### Example 5

Average CPU load on all hosts in multiple host groups that have the
specific tags.

    avg(last_foreach(/*/system.cpu.load?[(group="Servers A" or group="Servers B" or group="Servers C") and (tag="Service:" or tag="Importance:High")]))

[comment]: # ({/0233edd3-0233edd3})

[comment]: # ({30448f5d-30448f5d})
##### Example 6

Calculation used on the latest item value sums of a whole host group.

    sum(last_foreach(/*/net.if.out[eth0,bytes]?[group="video"])) / sum(last_foreach(/*/nginx_stat.sh[active]?[group="video"])) 

[comment]: # ({/30448f5d-30448f5d})

[comment]: # ({3e9404a6-3e9404a6})
##### Example 7

The total number of unsupported items in host group 'Zabbix servers'.

    sum(last_foreach(/*/zabbix[host,,items_unsupported]?[group="Zabbix servers"]))

[comment]: # ({/3e9404a6-3e9404a6})
