WestFarmer
WestFarmer

Reputation: 765

Is it possible to map prometheus label values according to another key-value pair variable?

I have a Prometheus metric like this:

lines_added{project="xx",user="xx"}

The project label and user label are integer ids, not good for legend on graph.

I have another variable members as query from a PostgreSQL data source:

select u.id as __value,u.name as __text 
from project_authorizations pa left join users u 
on pa.user_id = u.id 
where pa.project_id=[[project]]

For the lines_added metric, how can I make it display the user's real name according "id"->"name" mapping in variable members?

Is that possible with Grafana?

Upvotes: 8

Views: 2984

Answers (1)

markalex
markalex

Reputation: 13341

You don't need dashboard variables for this.

Current versions of Grafana support interpretation of time series as tables. This way those can be join similarly to join of SQL.

  1. Change the data source to --Mixed--
  2. In the panel editor, under the query: Options > Type: Table
  3. Add a new query, with data source being your DB, containing the real names
  4. Then Transform tab > Join by field: select common field of your data.

There is a catch though: the field should have the same name in both datasets, and only one field is allowed for joining.

Upvotes: 0

Related Questions