graphitebosun

How to use NumberExpr in graphite query in bosun


I use macro to define core calculations. And I'd like to have as less params to define for the macro as possible. So, I have a macro that base it's calculations on the variable $period. Then I try to use a variable that related to period in the graphite query, but I receive an error.

Simplified code:

# defined outside a macro
$period_min = 5

#macro, skipping irrelevant variables
$control_period_min = $period_min * 3

$periods = graphiteBand( $expr, "${control_period_min}m", "1h", "tag", 1 )

Produces:

graphiteBand: time: unknown unit * in duration 5 * 3m

I wonder, is it possible to implement the same logic different way?


Solution

  • Variables are just string replacement. Since you have put it in quotes, you are making a string that would be literally "5 * 3".

    What you can do is use the tod() function:

    # defined outside a macro
    $period_min = 5
    
    #macro, skipping irrelevant variables
    $control_period_min = $period_min * 3
    
    avg(q("avg:rate:os.cpu{host=*bosun*}", tod($control_period_min), ""))