How to handle "aspercent" when both input to it is zero


#1

I am using latest version of grafana, I am facing one issue because of “asPercent”. I am calculating failure percentage using “asPercent” ,

EX: asPercent(Total_failure_calls,Total_calls)
when both this variable has value we don’t have any problem, when both values are zero for that particular time stamp we are not getting any value(no point in graph) which will trigger “no data” alert.(I know that mathematically this value is NAN so we are not plotting any value, but this will trigger no data alert). So can we plot “Zero” when we get NAN from asPercent.

Note : I can’t make “null as zero” beacause , that change never trigger me “no data”

According to me , when both “Total_failure_calls” and “Total_calls” are zero we should return zero in that particular time stamp and we should trigger “no data” when any one value is not present.

Please give me some suggestion.

Thanks,
Sudhi


#2

You don’t mention it anywhere, are you talking about Graphite? Are you using subqueries? Can you transform “Total_calls” to 1 to avoid getting NaN?


#3

yes i am using graphite as a database.

Here is my grafana metric

alias(asPercent(idap_dep_poc.*.CPP.TOTAL_NUM_OF_FAIL_CALLS, #C), ‘PERCENTAGE_OF_TOTAL_NUM_OF_FAIL_CALLS’)

C --> Total Number of call

In real time (Each 5 min) I am getting data, possibility that I can get both value Zero . If value zero then “asPercent(0,0)” , So no value is plotted in graph which will result in “no data” alert.

Is any way I can make “Total_calls” as 1 ? (only if value is zero)

Thanks,
Sudhi


#4

Any update on this ?


#5

What version of Graphite are you using? Have you upgraded to the 1.0.x yet?

It has the transformNull function: https://graphite.readthedocs.io/en/latest/functions.html#graphite.render.functions.transformNull


#6

I am using graphite version “0.9.10”. I don’t think above solution will work. Because problem occur when I am getting both values in aspercent is “ZERO” (not null :)) . In this case output will NAN and “no data” alert will trigger. Also I can’t use “transformNull” (It is same as grafana option ““null as zero””) because in this case if I get actual “no data” then alert will not trigger.

So we can handle this

  1. change the output of aspercent to some default value say “0” , only if both input value of asperccent is zero. --> In this case if input is Null then “no_data” alert should trigger

  2. set no_data/null to “last value” --> in this case we are not getting “no_data” alert :frowning: and create separate dashboard for no_data (with out aspercent)


#7

Have you tried the offset function to add 1 to the total? But I can’t find a way to do “only if value is zero”. Otherwise your solution looks like it should work even if it isn’t as elegant.


#8

That is a cool idea to add “1” to the total number. In this way we can avoid "NAN"
But here I will never get “no_data” alert . I think we can’t set failure percent and “no_data” in same dashboard.
I will go for separate dashboard for “failure percentage” and “no_data” alert :slight_smile: