Ad Widget

Collapse

calculated items

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rsokoll
    Junior Member
    • Jun 2018
    • 11

    #1

    calculated items

    Hi,

    I want to know how many incoming bytes have crossed my router's eth0 within the last 30 days.
    From my understanding, I need a calculated item that substracts the value of last(//net.if[eth0],30d) from last(//net.if[eth0]​​​​), but that raises a syntax error:

    Code:
    Incorrect value for field "Formula": invalid second parameter in function "last".
    My formula is

    Code:
    last(//net.if[eth0]) - last(//net.if[eth0],30d)
    What am I missing?
  • Brambo
    Senior Member
    • Jul 2023
    • 245

    #2
    I think you should have
    Code:
    sum(last(//net.if[eth0]) - last(//net.if[eth0],30d))

    Comment

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

      #3
      Originally posted by Brambo
      I think you should have
      Code:
      sum(last(//net.if[eth0]) - last(//net.if[eth0],30d))
      That is pretty useless ... as it is wrong from the start...

      you have to remember that "last" is kind of special needs kid.. you cannot use last(/host/item,1d) to refer to a value one day ago... last has only "#num (optional) - the Nth most recent value". no "seconds" option..
      so if you want to refer to a value X time ago, you need to use time shift (last (/host/key,<#num<:time shift>>)​)​ https://www.zabbix.com/documentation...ion#time-shift
      I think "last(//net.if[eth0]) - last(//net.if[eth0],#1:now-30d)" should work...

      Comment

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

      #4
      valerio.bozzolan commented
      Yesterday, 12:16
      > you cannot use last(/host/item,1d) to refer to a value one day ago

      (Sorry for necroposting) Note that you mentioned the documentation of Zabbix 6.0, but that documentation also says that the `last()` function actually supports a "time shift parameter".

      See the documented syntax:

      ```
      last (/host/key,<#num<:time shift>>)
      ```
      Read again please..
      I have never claimed that it does not support time shift.. It has to be correctly formatted. You cannot use it as "...,30d", you need to format it as "...,#1,now-30d", ie last value from the moment of 30 days ago. which by all means can actually be whatever amount of time before that, it is just a last value before that 30d gap... We go back in time for 30 days and then look for last value from that moment.

      • I'm unsure if this is a bug in the Zabbix documentation. I'm just pretty much sure that:
        • - "last(//something)" works
          - "last(//something, #2)" works
          - "last(//something, 2)" does not work. Error: Invalid parameter "/1/params": invalid second parameter in function "last".
          - "last(//something, 2h)" does not work Error: Invalid parameter "/1/params": invalid second parameter in function "last".
      There is absolutely no bug here... omitting #X from parameters defaults to #1, ie last value. ",#2" refers to secoind to last value. ",2" and ",2h" do not work as last() has no "seconds" option.

      Comment

      Working...