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

1

8

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?

Metabolic answered 17/7, 2019 at 6:56 Comment(0)
R
0

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.

Ruth answered 15/4, 2023 at 7:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.