From a4af30675d9b40af3cc9a444a0a5efa85b64a7a1 Mon Sep 17 00:00:00 2001 From: Denis Doria Date: Mon, 10 Aug 2015 00:22:08 +0200 Subject: [PATCH 1/2] Included $col as an option for the "Alias pattern" on influxdb With this patch it's possible to use the column name as an identifier. This can help when we have multiple columns as it would be possible to automatic generate a legend. Also this would help in future when grafana could support the "AS" in the query builder. --- public/app/plugins/datasource/influxdb/influxSeries.js | 5 +++-- .../plugins/datasource/influxdb/partials/query.editor.html | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/public/app/plugins/datasource/influxdb/influxSeries.js b/public/app/plugins/datasource/influxdb/influxSeries.js index 43fb484e9ce..62ee43b5448 100644 --- a/public/app/plugins/datasource/influxdb/influxSeries.js +++ b/public/app/plugins/datasource/influxdb/influxSeries.js @@ -35,7 +35,7 @@ function (_) { } if (self.alias) { - seriesName = self._getSeriesName(series); + seriesName = self._getSeriesName(series, j); } else if (series.tags) { seriesName = seriesName + ' {' + tags.join(', ') + '}'; } @@ -54,13 +54,14 @@ function (_) { return output; }; - p._getSeriesName = function(series) { + p._getSeriesName = function(series, index) { var regex = /\$(\w+)|\[\[([\s\S]+?)\]\]/g; return this.alias.replace(regex, function(match, g1, g2) { var group = g1 || g2; if (group === 'm' || group === 'measurement') { return series.name; } + if (group === 'col') { return series.columns[index]; } if (group.indexOf('tag_') !== 0) { return match; } var tag = group.replace('tag_', ''); diff --git a/public/app/plugins/datasource/influxdb/partials/query.editor.html b/public/app/plugins/datasource/influxdb/partials/query.editor.html index 7df30e1fb0a..72d55ef08c2 100644 --- a/public/app/plugins/datasource/influxdb/partials/query.editor.html +++ b/public/app/plugins/datasource/influxdb/partials/query.editor.html @@ -210,6 +210,7 @@ From 696f8451cf99cc36bfd63f8ff41c0a61080c0f66 Mon Sep 17 00:00:00 2001 From: Denis Doria Date: Mon, 10 Aug 2015 08:12:12 +0200 Subject: [PATCH 2/2] Update documentation with $col alias --- docs/sources/datasources/influxdb.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/sources/datasources/influxdb.md b/docs/sources/datasources/influxdb.md index 05e627967eb..03dab9a362a 100644 --- a/docs/sources/datasources/influxdb.md +++ b/docs/sources/datasources/influxdb.md @@ -62,6 +62,7 @@ You can switch to raw query mode by pressing the pen icon. - $m = replaced with measurement name - $measurement = replaced with measurement name +- $col = replaced with column name - $tag_hostname = replaced with the value of the hostname tag - You can also use [[tag_hostname]] pattern replacement syntax