I do have a Prometheus time series with samples like these:
a_metric{band="1", state="A"} 1
a_metric{band="2", state="C"} 1
a_metric{band="1", state="A"} 1
a_metric{band="2", state="C"} 1
a_metric{band="1", state="B"} 1
a_metric{band="1", state="B"} 1
...
I would like to visualize this time series in a state timeline panel such that band
s become horizontal bands and state
s become discrete states within these bands. For this, I would have to extract values from the label state
(and use them instead of values 1).
Is this possible and can such a visualization be achieved?
If I understand correctly Prometheus' label_values()
cannot serve here, because it is restricted to templating. I suspect Grafana transformations could play a role, but I do not yet have experience with those. The complication also arises because Prometheus does not have string type metrics.
UPDATE Here is a basic image, as requested by @JanGaray.
suspect Grafana transformations could play a role
It is indeed possible with transformations.
table
Grouping to matrix
.
band
time
state
Convert field type
Time/<column>
Time
Value mappings
for each of the states you haveI'll show how the transformations work
To see what is happening in the transformations, it is always helpful to enable the as this will show actual returned data to the visualization.
Also toggling the transformations on and off using the
next to transformation really helps in seeing what is happening.
The state timeline visualization works best with a table as data source. Although it does support time series, the information we want to show is not a time series.
The visualization works best when the data is as follows.
🕓 Time | 🇦 Band 1 | 🇦 Band 2 |
---|---|---|
T1 | State A | State B |
T2 | State C | State A |
But when data is formatted as a time series the data will look like this:
🕓 Time | 🪟 {Band 1, State A} | 🪟 {Band 1, State C} | 🪟 ... |
---|---|---|---|
T1 | 1 | ||
T2 | 1 |
So first we need to set query format to from Timeseries
to Table
.
Expend the query options, and set format to Table.
When doing that our table will look like this.
🕓 Time | 🇦 band | 🇦 state | 🪟 Value |
---|---|---|---|
T1 | Band 1 | State A | 1 |
T1 | Band 2 | State B | 1 |
T2 | Band 1 | State C | 1 |
T2 | Band 1 | State A | 1 |
Next step is to pivot the table. For this we add the Grouping to matrix
transformation.
band
time
state
🇦 Time | 🇦 Band 1 | 🇦 Band 2 |
---|---|---|
1000 | State A | State B |
2000 | State C | State A |
Now there is just one problem left. The first column should be of data type time
but it is of type string
. You can see this by the icon infront of the column name. Indicated with emoji in my examples.
But this is an easy fix. Just add Convert field type
transformation below Grouping to matrix
transformation.
Time/<column>
Time
Now the table should look as follows:
🕓 Time | 🇦 Band 1 | 🇦 Band 2 |
---|---|---|
T1 | State A | State B |
T2 | State C | State A |
Following shows an example for ArgoCD. It shows the sync status for each application over time.
The prometheus exported data from ArgoCD looks as follows:
argocd_app_info{name="Application A", sync_state="Synced", ...} 1
argocd_app_info{name="Application B", sync_state="OufOfSync", ...} 1
argocd_app_info{name="Application C", sync_state="Unknown", ...} 1
argocd_app_info{name="Application D", sync_state="Synced", ...} 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With