Grafana-Loki variable datasource

Hello there,
I am using grafana-loki for my company. We have multiple servers with loki and promtail configured with docker-compose. In grafana ,we have mutiple datasources with loki for all the different servers. I am trying to configure a datasource variable for all servers that have loki but I couldn’t find a solution. To explain more , in the image coming I created a new variable(app) with type of datasource and then I selected Loki in datasource options. And in the blue section are all my servers that have Loki.


Then in the dashboard when I select for example 3 servers and the dashboard does not updates.
I don’t know what I do wrong. I tried also other types of variables but I think that are not global(for multiple servers with loki). Do you have any suggestions? I am really thankful for all ideas!!

Are you using the variable in your dashboards configuration?

Yes, but there are no results. Where do I have to put the variable? In the datasource section, in the label or in the value? I think in the datasource, but I tried all the different methods and I have no result. What else should I do?

Since your variable is meant to be used as data source, then yes you should use that variable in your data source part of dashboard. Can you link a screenshot of one of your dashboard configuration?

grafana-datasource-variable1

In the label section I have 3 options: job, filename and $datasource
In the value section I have again the datasource option along with the option in case I choose job or filename.
In case I choose job with $datasource as value I have no data, the same thing happens with filename and $datasource.

And in the last screenshot, I have all the environments with loki, but whatever I click nothing happens.
grafana-label

Looking at your second screenshot, you have the ${datasource} in the Data source section, that looks correct. But you also have it in your query {filename="$datasource"}, that looks incorrect, unless the filename in your log indeed matches datasource. Maybe try changing the query to something like {filename~=".+"} for testing purpose.

1 Like

Thank you for the recommendation. I did what you said.
grafana-var-cont

But the result from containerlogs in the dashboard, comes only from one datasource, for ex. alerts.
All the other datasources don’t appear.

Do I have to use Loki as multi-tenant, in order to take logs from multiple servers at the same time?

If yes, the only way possible is Kubernetes?

That’s what you were looking for, wasn’t it? To be able to select different data source based on variable? If not, perhaps clarify your question a bit.

You don’t need multi-tenant to take logs from multiple servers. You can separate log stream using labels.

You can deploy loki a couple of ways, Kubernetes is just one of them. Nothing to do with functionality.

1 Like

I am sorry for the misunderstanding.
I want to have one dashboard and from there to see all the logs from all my servers. Is that possible?
In the most servers I have 2 jobs: varlogs and containerlogs.
The datasousrce variable shows logs only from one loki instance that means just from one server. It can not take logs from at least two servers. I don’t know the reason this is happening.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.