How to determine the duration of a resolved alert?

I’m trying to figure out if there’s a way to determine the duration of a resolved alert. I know how to see when an alert started and ended using .StartsAt and .EndsAt, but I’m not sure how to calculate the duration in between.

Is there a method I can use to subtract .StartsAt from .EndsAt to get the delta? Or is there another way to determine the duration of a resolved alert?

Any help or advice would be greatly appreciated. Thank you!

2 Likes

I haven’t tried this but I don’t see support for invoking Golang’s packages in Grafana. Otherwise you could use functions from the time package to calculate the difference.

The list of supported functions is here: Templating labels and annotations | Grafana documentation

Maybe open a feature request at https://github.com/grafana/grafana/issues

were you able to get this resolved somehow? i am struggling getting alert duration after alert is resolved