Convert multi-metric state enum to single field for visualization

  • What Grafana version and what operating system are you using?
    Grafana v10.0.2 (b2bbe10fbc) via Docker

  • What are you trying to achieve?
    I have data coming in from Prometheus that looks like this:

    my_metric {universe="1",address="1",state="ok"} 1
    my_metric {universe="1",address="1",state="failed"} 0
    my_metric {universe="1",address="1",state="failed_due_to_adjacent"} 0
    my_metric {universe="1",address="2",state="ok"} 1
    my_metric {universe="1",address="2",state="failed"} 0
    my_metric {universe="1",address="2",state="failed_due_to_adjacent"} 0
    my_metric {universe="2",address="46",state="ok"} 0
    my_metric {universe="2",address="46",state="failed"} 0
    my_metric {universe="2",address="46",state="failed_due_to_adjacent"} 1
    my_metric {universe="2",address="47",state="ok"} 0
    my_metric {universe="2",address="47",state="failed"} 1
    my_metric {universe="2",address="47",state="failed_due_to_adjacent"} 0

    This effectively represents an enum called state for an instance uniquely identified by universe and address. When I show this in some visualizations I set the legend to {{universe}}.{{address}} to uniquely separate them.

    I am trying to end up with a visualization like state timeline where I can see a row for each {{universe}}.{{address}} and then the current state.

  • How are you trying to achieve it?
    I went into table view and then filtered where the value is greater than 0, but I’m not sure where to go from there. I can’t figure out how to combine the universe and address into one field (I need string concatenation there I think, with a separator in between).
    I think then I somehow need to map the different state values to numbers so that I can set value mappings for the names (or maybe there is a way to automatically use the state field as a value?).

  • What happened?

  • What did you expect to happen?

  • Can you copy/paste the configuration(s) that you are having problems with?
    N/A, I didn’t really get anywhere

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.

  • Did you follow any online instructions? If so, what is the URL?