Single graph with multiple plots for multi-value template variable

Hi,

I am using Prometheus datasource with Grafana. When I use a multi-value template variable for my queries, say A and B, I expect to get two separate graphs plotted in the same space, however i only get one graph with {A + B}, and the resultant is only the query output for the last value, i.e. B in this case. The image below illustrates what I can see.

I have tried repeat panels but that duplicates the graph and gives me two separate graphs for the same metric. I don’t want that. I want it to be plotted on the same graph. What do I have to do in order to have two separate graph lines plotted on the same graph based on the values my template variable receives? Any help will be much appreciated.

Thanks

Your query needs to be written so that it returns multiple series. Looks like it only return one series. Might need a group by clause.

If you want two separate graphs you need to use the repeat feature, where in panel general tab you specify what variable to repeat the panel for.

Thanks @torkel for getting back to me.

My query looks like this right now:

This gives me just one graph line. What else do you mean by a group by clause?

Try instance=~"$server" and in the legend format use {{instance}}

@torkel, When I enter {{instance}} in the legend format, it shows just the last value from the list of multi-value.

And I believe this is what it is doing even while dispaying the graph - only displaying for the last value. Any thoughts why this might be and how it could be fixed?

Thanks

thats because your Prometheus regex label filter looks wrong still. Did you try my suggested correction?

I did try that but it gives me a “Request Error”

Any suggestions?

I need to implement this feature in majority of my graphs… the feature of plotting graphs for all selected templated variables in a single graph. Your help with this will be much appreciated @torkel

Thanks

The syntax looks wrong in your latest screenshot, missing a closing curly brace } after instance=~"$server"

Apologies, I had tried it out correctly earlier but I got nothing, but while showing you the screenshot, I somehow missed the curly brace.

It says “No datapoints”…

Looks like it can’t fetch the server values because my targets have been enrolled as :9100, hence the regex.

How can we get it to plot for all the values? Need your help :slight_smile:

Not sure I understand, what is the query for your server variable? It should return the exact value of the instance labels. Or did you define the values in the server variable manually?

The query for my server variable returns “servername” and the instance is enrolled as “servername:9100”, hence the regex used in the graph query

The legend format and its output illustrates this.

Not defining the values manually. Hope this clears your question.

Well that cannot be right. Since you use it to filter instance labels, the server variable needs to be the complete value of a instance label. Update your server variable query to return full instance labels!

That makes sense! I just tried it and it works. Thanks you very much for your help! :slight_smile:

The same question as you,i am now polling the traffic of multiple interfaces , but i can not see the multiple interface on the same graph.

@torkel can you help me cuz i am a totally newcomer to grafana and develop

Help with what? Can you describe more?

I expect to get two separate graphs plotted in the same space, however i only get one graph with {A + B}, and the resultant is only the query output for the last value

Actually it’s the same question as the mathurj, but it seems that it is not the same type of issue

You need by(instance) to group metrics by label value