Extended grafana dashboard to display dimensions.

Before the dimensions on the Metrics tab were hardcoded,
now they are read from the URL and are filtered based on
the 'dim_' prefix.
Furthermore, modified the URL for the Graph Metrics button
to append dim_ prefix for dimensions.

Change-Id: I5f71b17ffba48f2cfbad9d299285b6deb9dccd6f
Story: 2001179
Task: 4914
This commit is contained in:
Georgia-Anna Farmaki 2017-07-20 16:37:25 +02:00
parent 9dc87decbf
commit 33a98e4381
2 changed files with 18 additions and 17 deletions

View File

@ -19,6 +19,22 @@ var dashboard;
// All url parameters are available via the ARGS object
var ARGS;
// Setup the metric dimensions.
var dimensions = [];
for (var key in ARGS) {
var isDimParam = key.startsWith("dim_");
if (isDimParam) {
var value = ARGS[key];
var dim = {
"key": key.substring(4),
"value": value
};
dimensions.push(dim);
}
}
// Intialize a skeleton with nothing but a rows array and service object
dashboard = {
rows : [],
@ -38,7 +54,6 @@ dashboard.time = {
var rows = 1;
var metricName = '';
var hostname = '';
var region = '';
if(!_.isUndefined(ARGS.rows)) {
rows = parseInt(ARGS.rows, 10);
@ -52,10 +67,6 @@ if(!_.isUndefined(ARGS.hostname)) {
hostname = ARGS.hostname;
}
if(!_.isUndefined(ARGS.region)) {
region = ARGS.region;
}
for (var i = 0; i < rows; i++) {
dashboard.rows.push({
@ -72,16 +83,7 @@ for (var i = 0; i < rows; i++) {
{
"aggregator": "avg",
"alias": hostname,
"dimensions": [
{
"key": "hostname",
"value": hostname
},
{
"key": "region",
"value": region
}
],
"dimensions": dimensions,
"metric": metricName,
"period": "300",
}
@ -94,5 +96,4 @@ for (var i = 0; i < rows; i++) {
});
}
return dashboard;

View File

@ -167,7 +167,7 @@ class GraphMetric(tables.LinkAction):
dimensions = datum['metrics'][0].get('dimensions', {})
query = "?metric=%s" % metric
for key, value in dimensions.iteritems():
query += "&%s=%s" % (key, value)
query += "&dim_%s=%s" % (key, value)
except AttributeError:
# Catches case where Grafana 2 is not enabled.
name = datum['metrics'][0]['name']