Ad Widget

Collapse

Problems with calculated item aggregate sum function in 6.4

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • haglefar
    Junior Member
    • Nov 2023
    • 3

    #1

    Problems with calculated item aggregate sum function in 6.4


    Hello!

    I'm trying to sum up all my running Hyper-V virtual machines.

    Have original item linked to "Windows by Zabbix agent"-template with the following info:

    Name: Number of virtual machines
    Type: Zabbix Agent
    Key: wmi.getall[root\cimv2,"Select Name from Win32_PerfFormattedData_BalancerStats_HyperVDynami cMemoryVM"]
    Type of information: Text

    This returns a JSON-array with all the names of the machines, and i use preprocessing to count the machines.
    This short JavaScript code:
    Code:
    const data = JSON.parse(value);
    
    var length = 0;
    
    for (var k in data)
      if (data.hasOwnProperty(k))
         length++;
    return length;
    This returns only the number of running VM's and works for all my Hyper-V hosts.

    The problem is when I'm trying to sum up all the running VM's in one item with the "Calculated item"-item.

    Zabbix documentation for 6.4 states that this is the correct way to use aggregate functions:

    aggregate_function(foreach_function(/host/key?[group="host group"],timeperiod))

    I have created a new host named Aggregate Checks (with Zabbix-agent as agent-type and address 127.0.0.1) and created a new "Calculated Item" with the following settings:

    Name: Sum of all virtual machines
    Key: wmisumallvms
    Type of information: Text
    Formula: sum(last_foreach(/*/wmi.getall[root\cimv2,"Select Name from Win32_PerfFormattedData_BalancerStats_HyperVDynami cMemoryVM"]?[group="Hypervisors"]))


    This returns the following error:
    Cannot evaluate expression: no input data for function at "sum(last_foreach(/*/wmi.getall[root\cimv2,"Select Name from Win32_PerfFormattedData_BalancerStats_HyperVDynami cMemoryVM"]?[group="Hypervisors"]))"

    I have also tried to create the item in the "Windows by Zabbix agent"-template, which throws the same error.

    Maybe someone here has been through the same process as me, and can shed some light on it.

    Hagle
  • haglefar
    Junior Member
    • Nov 2023
    • 3

    #2
    Hello again,

    Since the Zabbix-documentation is seriously lacking in how to configure calculated items I try my luck here again.
    I have since last time made some progress and switched from using WMI to a simple powershell-oneliner which gives me all the running machines on the host.

    Problem is still how to set up the sum() function. This is where I am now:
    Name: Sum of all virtual machines v4
    Key: system.run-sumvms
    Type of information: Numeric (float)​
    Formula:
    Code:
    sum(last_foreach(/*/system.run[powershell.exe -nologo -command (Get-VM ^| Where-Object { $_.State -eq 'Running' } ^| Measure-Object).Count]?[group="Databases"],5m))
    This returns the following error:
    Code:
    Cannot evaluate expression: no input data for function at "sum(last_foreach(/*/system.run[powershell.exe -nologo -command (Get-VM ^| Where-Object { $_.State -eq 'Running' } ^| Measure-Object).Count]?[group="Databases"],5m))"
    Any ideas here?
    The item runs fine on all the hosts in Database group and returns a number. All i want is to get the sum for all hosts in one item.

    Hagle

    Comment

    • cyber
      Senior Member
      Zabbix Certified SpecialistZabbix Certified Professional
      • Dec 2006
      • 4807

      #3
      I'm going by this page .. https://www.zabbix.com/documentation...regate/foreach
      Shouldn't it be ...
      Code:
      sum_foreach(/*/system.run[powershell.exe -nologo -command (Get-VM ^| Where-Object { $_.State -eq 'Running' } ^| Measure-Object).Count]?[group="Databases"])

      Comment

      • haglefar
        Junior Member
        • Nov 2023
        • 3

        #4
        Originally posted by cyber
        I'm going by this page .. https://www.zabbix.com/documentation...regate/foreach
        Shouldn't it be ...
        Code:
        sum_foreach(/*/system.run[powershell.exe -nologo -command (Get-VM ^| Where-Object { $_.State -eq 'Running' } ^| Measure-Object).Count]?[group="Databases"])
        I think if you use sum_foreach it will sum all values for that item for each host, no?
        Instead of the sum of the last item on each host.

        It does not work either way, even with what i think is the right parameters.

        Comment

        • cyber
          Senior Member
          Zabbix Certified SpecialistZabbix Certified Professional
          • Dec 2006
          • 4807

          #5
          I somehow doubt it will be summing whole history up... There is some default value probably, what docs unfortunately don't mention.. For less hurt, I would set default to "last".. but I really cannot tell right now, what goes on there...

          But I see your point.. but then again .. sum(last_foreach(...)) does not need that 5m time spec..
          Time period is ignored by the server if passed with the last_foreach function and can thus be omitted:​
          but then again, it should just ignore it, even if it exists...

          Just thinking out loud here...

          Comment

          • ISiroshtan
            Senior Member
            • Nov 2019
            • 324

            #6
            Just recently used similar setup with no issues, tho I was using min, not sum. Syntax example:
            min(last_foreach(/*/backend_active_pct?[group="My group"]))
            So 5m is indeed not needed, but also not supposed to break anything per my understanding. Assuming the key is correct and hostgroup Databases exists I don't see anything inherently wrong with it.

            Just to rule it out - I would create a dependent item with simpler key with no special symbols in it and would point it to your existing item with no extra preprocessings. Then would try aggregate over those dependent items with simpler key and see if it works.

            Comment

            • markfree
              Senior Member
              • Apr 2019
              • 868

              #7
              The problem is related to the type of item you are trying to aggregate.
              It was mentioned that the item is of type "text", therefore it is not possible to aggregate such an item.

              According to the documentation for "aggregate calculations",
              Only unsigned integers and float values (type of information) are supported for aggregate calculation items.
              Unfortunately, this information is not very clear and is only mentioned on the "aggregate calculations" page. The "Foreach functions" and "Aggregate functions" pages do not mention this limitation.
              There are also very few examples of aggregate calculations, and not for all functions.

              Comment

              Working...