3

I'm trying to visualize k8s pod lifetimes on their respective nodes as deployments occur. By following this answer, I've been able to get the layout I'm looking for:

current grafana panel

However, all the pod lifetimes for one node (one entire row) are the same color, until one hovers the mouse cursor over the graph - I'd like these to be different colors, so that it's easier to see the delineations at-a-glance.

Usually this would be done with Value Mappings - but in this case, the value names are randomly generated, and I can't possibly add mappings for all of them beforehand. I'd like Grafana to hash the value (string) to dynamically map that to a color - is there any way to do something like that?

Scott Minor
  • 137
  • 1
  • 7
  • Same issue here - I have (currently) 92 possible values that are partly nested. Your solution unfortunately is not applicable to my case. But thanks anyway for your effort! – akrea Mar 02 '23 at 08:42
  • 1
    @akrea Grafana has a JSON representation for dashboards - presumably, you could see what JSON fields are added for the Value Mappings, and then programmatically generate the mappings and upload/import the resulting JSON into grafana, instead of creating them all by hand via the GUI - as long as the 92 values are statically known – Scott Minor Mar 11 '23 at 00:05

1 Answers1

1

EDIT: In addition to the solution below for coloring, it can be useful to raise the Line width attribute on the State Timeline properties to show transition boundaries more clearly when successive elements are the same color, which can reduce the need for different coloring.


Turns out, it is possible to have Value Mappings that are regex-based - for this example, the random strings can be bucketed by a prefix, with a color assigned to each bucket. The random portion obeys the alphabet [a-z0-9], for a total of 36 characters. I created 18 regex-based Value mappings, each covering random strings that start with one of two characters (this is only slightly tedious):

regex value mappings

This is the result:

result

side note: For this usecase, it was also helpful to create a Special value mapping to match Empty and color it Transparent, to draw the gaps when there was no pod on a particular node.

To create a regex value mapping, click the Add a new mapping button in the Value mappings dialog:

regex mapping howto 1

and then pick Regex

regex mapping howto 2

Scott Minor
  • 137
  • 1
  • 7