Search code examples
bosun

How to handle NaN in Bosun?


I have 2 metrics and try to find the difference of average value between them in percentage like 100*(m1+m2)/m1 but this obviously produces NaN if m1 turns to zero.

How should I handle this case if I don't want to alert when the metrics turn to zero?


Solution

  • With bools bosun has a short-circuit like behavior. Since Bosun's expression language lacks if statements, you need to use a bool operation to see if the divisor is 0 first:

    $foo = 0
    $foo && 1/$foo
    

    Since $foo is zero, the statement is "not true" so 1/$foo is not factored into the final calculation:

    enter image description here