douyuben9434 2017-04-18 13:22
浏览 273
已采纳

Prometheus电子邮件警报以显示指标值

I have a label cs_job_time in Prometheus/Alert Manager and would like to send an email alert when a condition is met for another job. The email sends fine but is it possible to include the value of cs_job_time within the email? I can use {{$value}} for the metric in question but I would also like to print the value of cs_job_time.

I came across this but when I try

time = "{{  `cs_job_time{instance='%s', job='/'}` $labels.instance | query | first }}

or similar variants, I get the error message "Error expanding alert template CSJobAlert with data '{map[] 2123}': runtime error: invalid memory address or nil pointer dereference" source="alerting.go:199"

Is it possible to email metric values?

  • 写回答

1条回答 默认 最新

  • dounong5373 2017-04-18 13:36
    关注

    You're missing the printf there from the example:

    "{{ printf `cs_job_time{instance='%s', job='/'}` $labels.instance | query | first }}"
    

    Be careful though, if there's no results then the first will fail. It's generally best to use a range statement as that'll be resilient to that.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题