Hello everyone,
i am using the example script “scripted_templated.js” from grafana to create dashboards.
In that script i am using a templated variable “subService”, to get all values from a specific part of the metric.
For example the following metric: source.host.services.ping.ping.perfdata.$subService.value
My variable “subService” can be “pl” or “rta”.
This is working great so far.
Now i would like to access the variable “subService”.
The reason for that is that I want to find out which unit I have to set on the y-axis (“pl” is measured in percent and “rta” in milliseconds for example).
I found out, that you should use async dashboards for this scenario (https://github.com/grafana/grafana/issues/1308).
However i am not sure how to achieve this, as the documentation of the example script “scripted_async.js” is not very helpful for me and i can’t find anything on this forum for my problem.
Can someone give me an example on how i can access the template variables with async dashboards?
So far i got this and i just don’t know how i can access my template variable in JS:
...
return function(callback) {
...
var subServiceQuery = 'source.host.services.ping.ping.perfdata.*';
dashboard.templating = {
list: [
{
includeAll: true,
name: 'subService',
query: subServiceQuery,
refresh: 1,
type: 'query',
datasource: 'graphite'
}
]
};
$.ajax({
method: 'GET',
url: '/'
})
.done(function(result) {
dashboard.rows.push({
title: 'Chart',
height: '300px',
panels: [
{
title: seriesName + ' - ' + '$subService',
type: 'graph',
span: 12,
fill: 1,
id: rows,
linewidth: 2,
nullPointMode: "connected",
repeat: "subService",
targets: [
{
'target': target
}
],
seriesOverrides: [
{
alias: '/random/',
yaxis: 2,
fill: 0,
linewidth: 5
}
],
tooltip: {
shared: true
}
}
]
});
// when dashboard is composed call the callback
// function and pass the dashboard
callback(dashboard);
});
}
Many thanks.