如何格式化Bosun模板中的数字?

Jon*_*Jon 7 bosun

在Bosun模板中,是否可以将评估变量的输出格式化为较小的精度小数位?

简单示例:

template test_template{
    subject = test
    body = {{.Eval .Alert.Vars.average_runtime}} seconds
}
alert test_alert{
    template test_template
    $average_runtime = avg(q("avg:metric_name", "24h",""))
    crit = $average_runtime > 150.0
}
Run Code Online (Sandbox Code Playgroud)

结果是

190.71165892385326秒

在模板体中,这是不必要的精确.理想情况下,我希望看到:

190.71秒

cap*_*aig 3

在 go 模板中,您可以printf根据您想要的任何格式字符串来格式化输出。这个片段对我有用:

template test_template{
  subject = test
  body = {{printf "%.3f" (.Eval .Alert.Vars.average_runtime)}} seconds
}

alert test_alert{
  template = test_template
  $average_runtime = 1234.5678999
  crit = 1
}
Run Code Online (Sandbox Code Playgroud)