Create time series for alert history

We want to create a dashboard to see the alert history in time series.

Currently, what we were able to get a simple alert list using the alert list dashboard as the image shows image

However, we would like to show that same alert history as a time series. We have a query that goes like this:

from=“state-history”} | json | label_format status=`{{if contains “Alerting” .current}} 1 {{else}} 0 {{end}}

So that if the alert has been triggered it’s changed by 1, and 0 if it hasn’t been triggered. In transformations we are changing the status tu number. However, we get only one line when we should be having one line per each alertname.

Is there a way to achieve this? Thanks!

Welcome @rgg1993

Have you seen this blog post?

Grant, yes, I read that blog post among others, and wasn’t very helpful… However, I managed to do it.

I kept the query as presented below:

from=“state-history”} | json | label_format status=`{{if contains “Alerting” .current}} 1 {{else}} 0 {{end}}

And then in transformations organized the fields to keep only those that I needed, then another transformation to make sure that the 0 and 1 were interpreted as numbers and finally another transformation to partition by values. I’m posting the image below just in case it helps someone :slight_smile:

I doubt it’s an optimized solution, but guess I’ll figure out something better later on.