Search code examples
pythonzabbix

Zabbix 2.2 API get Processor load (1 min average) min/max value from_time, till_time


I want to get the CPU usage average/max for a month of a host (for 1 min average per core). I can get this in the Zabbix web gui CPU load graph.

I checked the pyzabbix example and the zabbix api document but I still don't know how to get the avg/max CPU usage from_time - till_time.

For example when I call:

history = zapi.history.get(itemids=[item_id],
        time_from=time_from,
        time_till=time_till,
        output='extend',
        limit='5000',
        history=0,
    )

I get many values of CPU usage for each 1 min from the range of time I use -> I have to use that data to calculate the min/avg/max ?

How Zabbix generate those kind of info in graph? Does it make a calculation like that every time we generate graph view?

Thanks


Solution

  • Yes, whenever a graph is generated in Zabbix, it fetches all historical data for the specified period and calculates minimum, average, and maximum values, in addition to plotting the graph.

    With Zabbix frontend itself, plotting graphs for longer periods of time is less heavyweight, because in such cases it takes the data from trend tables. For instance:

    mysql> describe trends;
    +-----------+---------------------+------+-----+---------+-------+
    | Field     | Type                | Null | Key | Default | Extra |
    +-----------+---------------------+------+-----+---------+-------+
    | itemid    | bigint(20) unsigned | NO   | PRI | NULL    |       |
    | clock     | int(11)             | NO   | PRI | 0       |       |
    | num       | int(11)             | NO   |     | 0       |       |
    | value_min | double(16,4)        | NO   |     | 0.0000  |       |
    | value_avg | double(16,4)        | NO   |     | 0.0000  |       |
    | value_max | double(16,4)        | NO   |     | 0.0000  |       |
    +-----------+---------------------+------+-----+---------+-------+
    6 rows in set (0.00 sec)
    

    Each row in this table corresponds to one hour and the minimum, average, and maximum values are stored for this hour. So when plotting a graph for a longer period of time, the frontend takes data from trends and has thus much less data to process.

    Unfortunately, trend data does not seem to be available through Zabbix API, but such a feature is requested in ZBXNEXT-1193.