feat(influxdb): More alias options, can now use syntax to reference part of a measurement name (seperated by dots), closes #2599

This commit is contained in:
Torkel Ödegaard
2015-09-04 07:40:28 +02:00
parent 97d42991a7
commit ead451a979
4 changed files with 24 additions and 1 deletions
@@ -56,12 +56,15 @@ function (_) {
p._getSeriesName = function(series, index) {
var regex = /\$(\w+)|\[\[([\s\S]+?)\]\]/g;
var segments = series.name.split('.');
return this.alias.replace(regex, function(match, g1, g2) {
var group = g1 || g2;
var segIndex = parseInt(group, 10)
if (group === 'm' || group === 'measurement') { return series.name; }
if (group === 'col') { return series.columns[index]; }
if (!isNaN(segIndex)) { return segments[segIndex]; }
if (group.indexOf('tag_') !== 0) { return match; }
var tag = group.replace('tag_', '');
@@ -51,6 +51,7 @@
<ul>
<li>$m = replaced with measurement name</li>
<li>$measurement = replaced with measurement name</li>
<li>$1 - $9 = replaced with part of measurement name (if you seperate your measurement name with dots)</li>
<li>$col = replaced with column name</li>
<li>$tag_hostname = replaced with the value of the hostname tag</li>
<li>You can also use [[tag_hostname]] pattern replacement syntax</li>
+18
View File
@@ -157,6 +157,24 @@ define([
});
describe('given measurement with dots', function() {
var options = { series: [
{
name: 'app.prod.server1.count',
tags: {},
columns: ['time', 'mean'],
values: [[1431946625000, 10], [1431946626000, 12]]
}
]};
it('should replace patterns', function() {
options.alias = 'alias: $1 -> [[3]]';
var series = new InfluxSeries(options);
var result = series.getTimeSeries();
expect(result[0].target).to.be('alias: prod -> count');
});
});
});
});