Ad Widget

Collapse

Help - zabbix calculated items

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Spectator
    Member
    • Sep 2021
    • 71

    #1

    Help - zabbix calculated items

    I want to display a calculated value.
    One value is a modbus query value.
    This is what this item looks like in Zabbix:

    Name: Active energy
    Type: Zabbix agent
    Key: modbus.get[rtu://{$MBPORT}:{$MBBAUDRATE}:{$MBDATABITS}{$MBPARITY}{$ MBSTOPBIT},{$MBID},3,24576,,float]
    Type of information: Numeric (float)
    Units: !kWh


    The current value of this measurement is 1410.27002

    I want to subtract the other value from this value.
    The other value is in a file:
    zabbix_get -s 127.0.0.1 -p 10050 -k vfs.file.contents[/tmp/powermeter_daily_beginning.txt]
    1400.310059

    I don’t want to measure this other value continuously in Zabbix, it’s just needed for subtraction.

    I created a new item:

    Name: Daily active energy
    Type: Calculated
    Key: daily.active.energy
    Type of information: Numeric (float)

    But the "Formula" .... has a problem with that.
    I tried this:

    (//modbus.get[rtu://{$MBPORT}:{$MBBAUDRATE}:{$MBDATABITS}{$MBPARITY}{$ MBSTOPBIT},{$MBID},3,20514,,float])-(//vfs.file.contents[/tmp/powermeter_daily_beginning.txt])

    Result:
    Cannot parse formula: item query must be first argument of a historical function at "//modbus.get[rtu://{$MBPORT}:{$MBBAUDRATE}:{$MBDATABITS}{$MBPARITY}{$ MBSTOPBIT},{$MBID},3,20514,,float])-(//vfs.file.contents[/tmp/powermeter_daily_beginning.txt])"

    last(//modbus.get[rtu://{$MBPORT}:{$MBBAUDRATE}:{$MBDATABITS}{$MBPARITY}{$ MBSTOPBIT},{$MBID},3,20514,,float])-(//vfs.file.contents[/tmp/powermeter_daily_beginning.txt])

    Result:
    Cannot parse formula: item query must be first argument of a historical function at "//vfs.file.contents[/tmp/powermeter_daily_beginning.txt])"


    last(//modbus.get[rtu://{$MBPORT}:{$MBBAUDRATE}:{$MBDATABITS}{$MBPARITY}{$ MBSTOPBIT},{$MBID},3,20514,,float])-last(//vfs.file.contents[/tmp/powermeter_daily_beginning.txt])

    Result:
    Cannot evaluate function: item "/Pro1-mod_native/modbus.get[rtu://{$MBPORT}:{$MBBAUDRATE}:{$MBDATABITS}{$MBPARITY}{$ MBSTOPBIT},{$MBID},3,20514,,float]" does not exist at "last(//modbus.get[rtu://{$MBPORT}:{$MBBAUDRATE}:{$MBDATABITS}{$MBPARITY}{$ MBSTOPBIT},{$MBID},3,20514,,float])-last(//vfs.file.contents[/tmp/powermeter_daily_beginning.txt])".


    How could I implement this subtraction?
  • LenR
    Senior Member
    • Sep 2009
    • 1005

    #2
    I think both must be items, so load your value from the file into Zabbix as an item, then subtract one item from the other.

    Comment

    • Spectator
      Member
      • Sep 2021
      • 71

      #3
      Dear LenR,

      Thanks for your response!

      I added the value in the text file to Zabbix as a new item:

      Name: AEBD
      Type: Zabbix agent
      Key:vfs.file.contents[/tmp/powermeter_daily_beginning.txt]
      Type of information: text (but I tried Numeric (float) also)

      The contents of this txt file currently: 1413.040039 and the zabbix shows it correctly.

      And to get started in a simpler way, subtracting the AEBD value from a fixed static number, I wanted to get the new calculated item.
      That is, 5000 minus the contents of the /tmp/powermeter_daily_beginning.txt file. So I want to subtract 1413.040039 from 5000.

      I created a new calculated item with this paramters:
      Name: Active energy - daily calculated
      Type: Calculated
      Key: daily.active.energy
      Type of information: Numeric (float)
      Formula... I tried these with the following results:

      (5000)-last(//vfs.file.contents[/tmp/powermeter_daily_beginning.txt])
      Cannot evaluate function: item "/Pro1-mod_native/vfs.file.contents[/tmp/powermeter_daily_beginning.txt]" does not exist at "last(//vfs.file.contents[/tmp/powermeter_daily_beginning.txt])"

      (5000)-last(/vfs.file.contents[/tmp/powermeter_daily_beginning.txt])
      Cannot parse formula: invalid item query starting at "/vfs.file.contents[/tmp/powermeter_daily_beginning.txt])"

      (5000)-last(vfs.file.contents[/tmp/powermeter_daily_beginning.txt])
      Cannot parse formula: invalid token starting with "vfs.file.contents[/tmp/powermeter_daily_beginning.txt])"

      (5000)-last(AEBD)
      Cannot parse formula: invalid token starting with "AEBD)"

      (5000)-last(/AEBD)
      Cannot parse formula: invalid item query starting at "/AEBD)"

      (5000)-last(//AEBD)
      Cannot evaluate function: item "/Pro1-mod_native/AEBD" does not exist at "last(//AEBD)"

      I don't think there are any more variations ...
      How should a numeric value read from a txt file be subtracted from a fixed number? I'm clueless...

      Comment

      Working...