From 33a98e4381ab8388685f89ca316fdfb3304261b2 Mon Sep 17 00:00:00 2001 From: Georgia-Anna Farmaki Date: Thu, 20 Jul 2017 16:37:25 +0200 Subject: [PATCH] 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 --- grafana-dashboards/drilldown.js | 33 +++++++++++++++++---------------- monitoring/alarms/tables.py | 2 +- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/grafana-dashboards/drilldown.js b/grafana-dashboards/drilldown.js index d1477952..30e28000 100644 --- a/grafana-dashboards/drilldown.js +++ b/grafana-dashboards/drilldown.js @@ -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; diff --git a/monitoring/alarms/tables.py b/monitoring/alarms/tables.py index 8b4ee9c5..1a7eb5ed 100644 --- a/monitoring/alarms/tables.py +++ b/monitoring/alarms/tables.py @@ -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']