Просмотр исходного кода

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.
Denis Doria 10 лет назад
Родитель
Сommit
a4af30675d

+ 3 - 2
public/app/plugins/datasource/influxdb/influxSeries.js

@@ -35,7 +35,7 @@ function (_) {
         }
         }
 
 
         if (self.alias) {
         if (self.alias) {
-          seriesName = self._getSeriesName(series);
+          seriesName = self._getSeriesName(series, j);
         } else if (series.tags) {
         } else if (series.tags) {
           seriesName = seriesName + ' {' + tags.join(', ') + '}';
           seriesName = seriesName + ' {' + tags.join(', ') + '}';
         }
         }
@@ -54,13 +54,14 @@ function (_) {
     return output;
     return output;
   };
   };
 
 
-  p._getSeriesName = function(series) {
+  p._getSeriesName = function(series, index) {
     var regex = /\$(\w+)|\[\[([\s\S]+?)\]\]/g;
     var regex = /\$(\w+)|\[\[([\s\S]+?)\]\]/g;
 
 
     return this.alias.replace(regex, function(match, g1, g2) {
     return this.alias.replace(regex, function(match, g1, g2) {
       var group = g1 || g2;
       var group = g1 || g2;
 
 
       if (group === 'm' || group === 'measurement') { return series.name; }
       if (group === 'm' || group === 'measurement') { return series.name; }
+      if (group === 'col') { return series.columns[index]; }
       if (group.indexOf('tag_') !== 0) { return match; }
       if (group.indexOf('tag_') !== 0) { return match; }
 
 
       var tag = group.replace('tag_', '');
       var tag = group.replace('tag_', '');

+ 1 - 0
public/app/plugins/datasource/influxdb/partials/query.editor.html

@@ -210,6 +210,7 @@
 			<ul>
 			<ul>
 				<li>$m = replaced with measurement name</li>
 				<li>$m = replaced with measurement name</li>
 				<li>$measurement = replaced with measurement name</li>
 				<li>$measurement = replaced with measurement name</li>
+				<li>$col = replaced with column name</li>
 				<li>$tag_hostname = replaced with the value of the hostname tag</li>
 				<li>$tag_hostname = replaced with the value of the hostname tag</li>
 				<li>You can also use [[tag_hostname]] pattern replacement syntax</li>
 				<li>You can also use [[tag_hostname]] pattern replacement syntax</li>
 			</ul>
 			</ul>