Ad Widget

Collapse

Calculated item with function "last" and time shift

Collapse
This topic has been answered.
X
X
 
  • Time
  • Show
Clear All
new posts
  • josoko
    Junior Member
    • Feb 2021
    • 25

    #1

    Calculated item with function "last" and time shift

    Hello

    I do not understand how I can use the time shift for a calculated item, to calculate the change in % from the last value with a value which Zabbix has collected 1h (or 3h, or 1day) before the last value.

    Origin Item:
    - name: Value XY
    - key: value[xy]
    - interval 5m

    This item below is working fine.

    Calculated Item:
    - name: Change in % Value XY
    - key: ci.valuechange[xy,5m]
    - calculation: round(((last(//value[xy]) - last(//value[xy],#2)) / last(//value[xy],#2)) * 100,4)


    This item below is not working and I cannot figure out why. All calculations failed.

    Calculated Item:
    - name: Change in % Value XY
    - key: ci.valuechange[xy,1h]

    calculations:
    round(((last(//value[xy]) - last(//value[xy],1h:now)) / last(//value[xy],1h:now) * 100,4)
    round(((last(//value[xy]) - last(//value[xy],now-1h)) / last(//value[xy],now-1h) * 100,4)
    round(((last(//value[xy]) - last(//value[xy],1h)) / last(//value[xy],1h) * 100,4)
    round(((last(//value[xy]) - last(//value[xy],#1:now-1h)) / last(//value[xy],#1:now-1h) * 100,4)
    round(((last(//value[xy]) - last(//value[xy],#1:1h)) / last(//value[xy],#1:1h) * 100,4)


    I would appreciate it if somebody could explain to me, what's wrong with the time shift in my calculations,
  • Answer selected by josoko at 05-06-2022, 19:30.
    Markku
    Senior Member
    Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
    • Sep 2018
    • 1781

    This works for me:

    round((last(//my_item)-last(//my_item,#1:now-1h))/last(//my_item,#1:now-1h) * 100, 2)

    Your formulas have incorrect parenthesis I see.

    Markku

    Comment

    • Markku
      Senior Member
      Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
      • Sep 2018
      • 1781

      #2
      I haven't used time shifts much at all but let's see according to the documentation.

      https://www.zabbix.com/documentation...mon-parameters says that last() doesn't accept time spec, so your calculations 1, 2 and 3 are incorrect right away.

      https://www.zabbix.com/documentation...ion#time-shift says that time shift starts with "now", so your 5 is incorrect.
      That leaves 4 the only one that is correct by syntax (as far as I see it). I don't have direct answer why it doesn't work.

      For me the whole concept of "last value 1 hour ago" is a bit vague. For example, if it is 11:00 at the moment and there are values at 09:59 and 10:01 (but not at 10:00), which one should it choose?

      Markku

      Comment

      • Markku
        Senior Member
        Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
        • Sep 2018
        • 1781

        #3
        Btw, what does "All calculations failed." mean?

        Markku

        Comment

        • Markku
          Senior Member
          Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
          • Sep 2018
          • 1781

          #4
          This works for me:

          round((last(//my_item)-last(//my_item,#1:now-1h))/last(//my_item,#1:now-1h) * 100, 2)

          Your formulas have incorrect parenthesis I see.

          Markku

          Comment

          • josoko
            Junior Member
            • Feb 2021
            • 25

            #5
            Markku , Indeed. It was an issue with the parenthesis. That works now:

            round((last(//value[xy]) - last(//value[xy],#1:now-1h)) / last(//value[xy],#1:now-1h) * 100,4)

            The origin calculation is wrong as well. It surprises me, that Zabbix has not dropped an error message here:

            Wrong:
            round(((last(//value[xy]) - last(//value[xy],#2)) / last(//value[xy],#2)) * 100,4)


            Should be:
            round((last(//value[xy]) - last(//value[xy],#2)) / last(//value[xy],#2) * 100,4)

            Many thx! You solved my problem. Have a nice weekend!

            Comment

            Working...