Postgres data source issue with All option in variable

I have a database with IP,TEAM,OWNER and OS as attributes.

In grafana I want to filter with team variable so that I can get team and owner details. But if I include all option in team variable I am not getting data. I declared varibles in grafana metioned below:

team: select team from server;
owner: select owner from server where team=’$team’;
ip: select ip from server where team=’$team’;

here if I select particular team I am getting details but if I select all option I am not getting data.

how can I change my variables so that it will display correctly for all option

thanks in advance

@griks88 @fadjar340
hello guys. could anyone of you please help me?

Try this:

team: select team from server;
owner: select owner from server where team in ’$team’;
ip: select ip from server where team in ’$team’;

@fadjar340 No sir… It’s not working… I am not getting any values of owner and ip in preview of values while declaring variables

Sorry… My bad…

Try this:

owner: select owner from server where team in (’$team’);
ip: select ip from server where team in (’$team’);

@fadjar340 heyy… tried but its too not working… same I am not getting any values in preview of values while declaring variables.

Try this also:

owner: select owner from server where team in ($team);
ip: select ip from server where team in ($team);

Also check the include All in the first variable

Because the $team is not string, its a variable…

@fadjar340 I am getting preview of values… but in grafana I am not getting values… I will attach few pics


If I select one particular team I am getting exactly… But if I select all I am getting only postgre values I am not getting prometheus data values.

What is the query in the second image?
I need to know if there some invalid syntax…

@fadjar340 there is nothing change in query… in first image I select particular team and in 2nd image I select all option… I will attach the queries and variables that I used in the dashboard





Hi…

Try do not select instant radio button, then look the result. The instant radio button just show the last value. If not using instant, you can use the time picker and make the calculation in the table using transformation to get the last(not null) option.

But be careful with the time, if too long, grafana will get all the data from the postgres related to the time span. Better hide the time picker and put it as needed properly.

Regards,
Fadjar T

@fadjar340 I tried all the methods but nothing got worked. I didn’t understand where it is going wrong

@fadjar340
Hello.

Actually I am using two data sources (prometheus and postgre). If I select ALL option in team variable I am not able to see any info of owner and ip so I am not able to see prometheus data. but if I change ip to instance( like in query I declared like instance=~"$ip:9100", instead of this if I declare like instance=~"$instance" I am getting values but only one ip value I am getting others I am not getting)
Like what can be the reason for that?

Thanks in advance

You need to make sure the result of the variable instance and ip is the same value. If not you need to modify query.

@fadjar340 yes sir… like as you said I modified and everything looks fine. I am getting everything correct except one thing is like if we select team I am getting all team details in every team(like I am getting the all server details irrespective of team). How to overcome that? Will it possible?

@fadjar340 sir can we remove port number from instance. The instance is in the table, its not the separate panel. could you please help me?

Hello , I use this syntax: where team in (’${teams:csv}’)

@justain but I am not using any csv file.

csv is the format Posgresql will accept in the “in” statement: where team in (‘team1’,‘team2’)