Combine same metric of multiple hosts in a single graph


I have been looking around the forums / google for help for quite some time and I can’t figure out a solution to an issue we are experiencing.
We want to graph data that comes from Opentsdb for a specific metric (let’s say ‘memory’)

The metric name would be like hostname_memory_memory
We defined our hostnames in a custom variable like:
hostname1, hostname2, hostname3, hostname4

Right now, we are repeating a single graph per host, so we have 4 different graphs with:


Instead, we want a single graph that contains the memory metric for these 4 hosts.
I couldn’t find an answer to this issue, but I might have missed something.

Could someone assist? Our Grafana version is v4.6.1 (commit: cac8b97)

Thank you in advance!

1 Like

If you mean showing the 4 different hosts on the same graph/panel, you can create multiple queries and they will all show up in the same panel.

You should be able to do the same thing with a single query with pattern matching, though I’m not up to speed on opentsdb to help with that.

If you need something else, a screenshot or more detail would help :slight_smile:

1 Like


Thank you for your reply! What you describe would indeed be the intended goal, I am simply wondering if we can do this in a dynamic way so we don’t have to add the queries manually?

For example, in pseudo I would explain it as:

$hosts = hostname1, hostname2, hostname3, hostname4
for each $host in $hosts:
    - query Opentsdb #(unless we can query once and distribute the data over the hosts in one graph)
    - draw a line on the (same) graph

So without us needing to create a query per host we want to add, but that it creates it for us based on the $hosts (custom) variable that we have created in the dashboard (or just use a single query and plot them all correctly)

I couldn’t find a way of doing this? Is it possible this does not exist?

Yes you can do this with a template variable.

You can create a template variable that contains a query that gets the list of hostnames (or hardcode it to test in CSV format), and use that template variable in the query.

Like this:

Once you have a template variable created, you will see a dropdown/selector at the top left of the dashboard where you can choose servers.

In the query you would use $servers instead of a server name.

If you have the opentsdb query I may be able to assist with that.


We have indeed defined it like that and then use $servers in the query, but the issue is that if we then select the “all” option, it seems to use ALL the hostnames (like “hostname1 | hostname2 | hostname3_metricname”) for the graph.

We don’t want seperate graphs per hostname, we want them combined into one.

We can for example graph this when we have the selection on top for a specific host, but if we change it to ‘all’ it is unable to plot them all on a single graph (which is what we want).

Don’t know much about OpentsDB but, have you tried to use:

Metric -> /.*_memory_memory/

That way it will match all your hostnames…


I tried this and it says no metric found :frowning:

Mmm, and what about if you start writing memory…
Does it show anything with autocompleting?


Hi jorisvk,

Just play a bit with Graf > edit > General > Repeating

and I’m sure you will find how it works.

Did you find any way to dynamically add queries to panel?