Ad Widget

Collapse

Calculating item: chose the max value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dimenty
    Junior Member
    • Apr 2015
    • 18

    #1

    Calculating item: chose the max value

    Hi, i need some help with calculating items.
    I got 2 items (i get values via snmp at the same time) and i need 3rd item that will compare these 2 values and chose max value. How can i create this item?
  • Dimenty
    Junior Member
    • Apr 2015
    • 18

    #2
    up up up up up

    Comment

    • glebs.ivanovskis
      Senior Member
      • Jul 2015
      • 237

      #3
      Maybe this will help you.

      Comment

      • Dimenty
        Junior Member
        • Apr 2015
        • 18

        #4
        Thanks! That really what i need. Why there is no information about that trick in documentation?

        Comment

        • glebs.ivanovskis
          Senior Member
          • Jul 2015
          • 237

          #5
          I think our documentation person has been too busy documenting 3.0 features recently.

          Comment

          • Dimenty
            Junior Member
            • Apr 2015
            • 18

            #6
            I got a strange issue with "<=" sign in formula. When i use "<=" in formula, it returns 0 even if the left value less then the right. When i use ">=" sign - is ok.

            So for max item its better to use this
            (item1 >= item2) * item1 +
            (item1 < item2) * item2
            or this
            (item1 > item2) * item1 +
            (item1 < item2) * item2 +
            (item1 = item2) * item1

            This formula
            (item1 > item2) * item1 + (item1 <= item2) * item2
            returns 0 because of <= sign

            I have no idea what's wrong with it

            Comment

            • glebs.ivanovskis
              Senior Member
              • Jul 2015
              • 237

              #7
              Can you give me actual numbers?

              Comment

              • Dimenty
                Junior Member
                • Apr 2015
                • 18

                #8
                Do you mean real formula?
                Code:
                (last("avgIncomingIn10Mins[{#SNMPVALUE}]") > last("avgOutcomingIn10Mins[{#SNMPVALUE}]")) * last("avgIncomingIn10Mins[{#SNMPVALUE}]") + 
                (last("avgIncomingIn10Mins[{#SNMPVALUE}]") <= last("avgOutcomingIn10Mins[{#SNMPVALUE}]")) * last("avgOutcomingIn10Mins[{#SNMPVALUE}]")
                If you want real values of my items (avgIncomingIn10Mins and avgOutcomingIn10Mins), i could tell you that they are not 0, because they store actual speed on working router port.


                --------------

                And suddenly i discovered that >= is also doesnt work and returns 0.
                So the best way to compare 2 items is that formula.
                Code:
                (item1 > item2) * item1 +
                (item1 < item2) * item2 +
                (item1 = item2) * item1
                Last edited by Dimenty; 19-02-2016, 12:26.

                Comment

                • glebs.ivanovskis
                  Senior Member
                  • Jul 2015
                  • 237

                  #9
                  I was thinking of the actual numbers because comparison operators work in a very tricky way and some round-off magic can take place.

                  Actually, a new value can be obtained in the middle of expression evaluation. In this case your third expression will return 0 like two previous.

                  Comment

                  • Dimenty
                    Junior Member
                    • Apr 2015
                    • 18

                    #10
                    Numbers that i compare are huge (9-11 digits) so i think there is no rounding problems.

                    Actually, a new value can be obtained in the middle of expression evaluation. In this case your third expression will return 0 like two previous.
                    Sorry, but i can't catch what are you talking about.

                    Comment

                    • glebs.ivanovskis
                      Senior Member
                      • Jul 2015
                      • 237

                      #11
                      Originally posted by Dimenty
                      Sorry, but i can't catch what are you talking about.
                      How Zabbix calculates trigger expressions? Let's evaluate this one:
                      Code:
                      (item1 >= item2) * item1 +
                      (item1 < item2) * item2
                      Let's assume last value of item1 is 1 and last value of item2 is 1. (1 >= 2) evaluates to 0 (false) and 0 * 1 evaluates to 0. Now a new value for item1 comes in, let's say 3. (3 < 2) evaluates to 0 and 0 * 2 evaluates to 0. 0 + 0 is 0.

                      Comment

                      • Dimenty
                        Junior Member
                        • Apr 2015
                        • 18

                        #12
                        I still don't understand how can your values of item1 and item2 can be different at the same time. They are equal on every iteration.

                        1st iteration.
                        i1=5, i2=3.
                        (5>3)*5 + (5<=3)*3 = 1*5+0*3 = 5.

                        On the next iteration there will be another values.
                        i1=2, i2=6.
                        (2>6)*2 + (2<=6)*6 = 0*2+1*6 = 6.

                        But when i use >= or <= signs in formula it returns 0.
                        So i need a 3rd part of my formula with = sign:
                        i1=5, i2=3.
                        (5>3)*5 + (5<3)*3 + (5=3)*5 = 1*5+0*3+0*5 = 5.

                        Comment

                        • glebs.ivanovskis
                          Senior Member
                          • Jul 2015
                          • 237

                          #13
                          Can you then explain how did you get 0 with <= or >= signs?

                          Comment

                          • Dimenty
                            Junior Member
                            • Apr 2015
                            • 18

                            #14
                            I have no idea why i get 0. Thats why i refused to use <= or >= in formula

                            Comment

                            Working...