2014-02-27 21:46:06 +01:00
|
|
|
define([
|
|
|
|
|
'angular',
|
2014-08-07 14:35:19 +02:00
|
|
|
'lodash',
|
2014-07-01 15:55:56 +02:00
|
|
|
'kbn',
|
|
|
|
|
'./influxSeries'
|
2014-02-27 21:46:06 +01:00
|
|
|
],
|
2014-07-01 15:55:56 +02:00
|
|
|
function (angular, _, kbn, InfluxSeries) {
|
2014-02-27 21:46:06 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
2014-07-28 18:11:52 +02:00
|
|
|
var module = angular.module('grafana.services');
|
2014-02-27 21:46:06 +01:00
|
|
|
|
2014-08-27 16:29:48 +02:00
|
|
|
module.factory('InfluxDatasource', function($q, $http, timeSrv) {
|
2014-02-27 21:46:06 +01:00
|
|
|
|
|
|
|
|
function InfluxDatasource(datasource) {
|
|
|
|
|
this.type = 'influxDB';
|
2014-03-03 06:53:50 +01:00
|
|
|
this.editorSrc = 'app/partials/influxdb/editor.html';
|
2014-03-28 01:13:11 -04:00
|
|
|
this.urls = datasource.urls;
|
2014-02-27 21:46:06 +01:00
|
|
|
this.username = datasource.username;
|
|
|
|
|
this.password = datasource.password;
|
2014-03-02 10:41:16 +01:00
|
|
|
this.name = datasource.name;
|
2014-03-01 12:02:55 +01:00
|
|
|
this.templateSettings = {
|
|
|
|
|
interpolate : /\[\[([\s\S]+?)\]\]/g,
|
|
|
|
|
};
|
2014-07-13 15:01:20 +02:00
|
|
|
|
2014-08-03 12:07:50 +02:00
|
|
|
this.saveTemp = _.isUndefined(datasource.save_temp) ? true : datasource.save_temp;
|
|
|
|
|
this.saveTempTTL = _.isUndefined(datasource.save_temp_ttl) ? '30d' : datasource.save_temp_ttl;
|
|
|
|
|
|
2014-07-30 15:32:15 +02:00
|
|
|
this.grafanaDB = datasource.grafanaDB;
|
2014-07-13 15:01:20 +02:00
|
|
|
this.supportAnnotations = true;
|
2014-07-30 08:34:58 +02:00
|
|
|
this.supportMetrics = true;
|
2014-07-13 15:01:20 +02:00
|
|
|
this.annotationEditorSrc = 'app/partials/influxdb/annotation_editor.html';
|
2014-02-27 21:46:06 +01:00
|
|
|
}
|
|
|
|
|
|
2014-08-27 16:29:48 +02:00
|
|
|
InfluxDatasource.prototype.query = function(options) {
|
2014-03-02 10:41:16 +01:00
|
|
|
var promises = _.map(options.targets, function(target) {
|
2014-03-28 01:13:11 -04:00
|
|
|
var query;
|
2014-06-06 10:56:23 +02:00
|
|
|
var alias = '';
|
2014-03-28 01:13:11 -04:00
|
|
|
|
|
|
|
|
if (target.hide || !((target.series && target.column) || target.query)) {
|
2014-03-02 10:41:16 +01:00
|
|
|
return [];
|
|
|
|
|
}
|
2014-02-27 21:46:06 +01:00
|
|
|
|
2014-03-28 01:13:11 -04:00
|
|
|
var timeFilter = getTimeFilter(options);
|
2014-06-14 14:38:14 +02:00
|
|
|
var groupByField;
|
2014-02-27 21:46:06 +01:00
|
|
|
|
2014-03-28 01:13:11 -04:00
|
|
|
if (target.rawQuery) {
|
|
|
|
|
query = target.query;
|
|
|
|
|
query = query.replace(";", "");
|
|
|
|
|
var queryElements = query.split(" ");
|
|
|
|
|
var lowerCaseQueryElements = query.toLowerCase().split(" ");
|
|
|
|
|
var whereIndex = lowerCaseQueryElements.indexOf("where");
|
|
|
|
|
var groupByIndex = lowerCaseQueryElements.indexOf("group");
|
|
|
|
|
var orderIndex = lowerCaseQueryElements.indexOf("order");
|
|
|
|
|
|
2014-06-22 12:01:41 +02:00
|
|
|
if (lowerCaseQueryElements[1].indexOf(',') !== -1) {
|
2014-06-14 14:38:14 +02:00
|
|
|
groupByField = lowerCaseQueryElements[1].replace(',', '');
|
|
|
|
|
}
|
2014-03-28 01:13:11 -04:00
|
|
|
|
|
|
|
|
if (whereIndex !== -1) {
|
2014-06-07 06:38:33 +02:00
|
|
|
queryElements.splice(whereIndex + 1, 0, timeFilter, "and");
|
2014-03-28 01:13:11 -04:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (groupByIndex !== -1) {
|
|
|
|
|
queryElements.splice(groupByIndex, 0, "where", timeFilter);
|
|
|
|
|
}
|
|
|
|
|
else if (orderIndex !== -1) {
|
|
|
|
|
queryElements.splice(orderIndex, 0, "where", timeFilter);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
queryElements.push("where");
|
|
|
|
|
queryElements.push(timeFilter);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
query = queryElements.join(" ");
|
2014-08-27 16:29:48 +02:00
|
|
|
query = timeSrv.applyTemplateToTarget(query);
|
2014-03-28 01:13:11 -04:00
|
|
|
}
|
|
|
|
|
else {
|
2014-06-14 14:38:14 +02:00
|
|
|
|
2014-06-22 18:02:43 +02:00
|
|
|
var template = "select [[group]][[group_comma]] [[func]]([[column]]) from [[series]] " +
|
2014-04-21 18:07:24 +02:00
|
|
|
"where [[timeFilter]] [[condition_add]] [[condition_key]] [[condition_op]] [[condition_value]] " +
|
2014-05-22 20:09:02 -07:00
|
|
|
"group by time([[interval]])[[group_comma]] [[group]] order asc";
|
2014-04-21 16:32:05 +02:00
|
|
|
|
2014-03-28 01:13:11 -04:00
|
|
|
var templateData = {
|
|
|
|
|
series: target.series,
|
|
|
|
|
column: target.column,
|
|
|
|
|
func: target.function,
|
|
|
|
|
timeFilter: timeFilter,
|
2014-04-21 18:07:24 +02:00
|
|
|
interval: target.interval || options.interval,
|
2014-06-14 14:38:14 +02:00
|
|
|
condition_add: target.condition_filter ? 'and' : '',
|
2014-05-22 18:18:22 -07:00
|
|
|
condition_key: target.condition_filter ? target.condition_key : '',
|
|
|
|
|
condition_op: target.condition_filter ? target.condition_op : '',
|
|
|
|
|
condition_value: target.condition_filter ? target.condition_value : '',
|
2014-05-22 20:09:02 -07:00
|
|
|
group_comma: target.groupby_field_add && target.groupby_field ? ',' : '',
|
2014-05-22 18:11:04 -07:00
|
|
|
group: target.groupby_field_add ? target.groupby_field : '',
|
2014-03-28 01:13:11 -04:00
|
|
|
};
|
|
|
|
|
|
2014-06-17 22:35:31 +10:00
|
|
|
if(!templateData.series.match('^/.*/')) {
|
2014-06-17 18:09:10 +02:00
|
|
|
templateData.series = '"' + templateData.series + '"';
|
2014-06-17 22:35:31 +10:00
|
|
|
}
|
|
|
|
|
|
2014-03-28 01:13:11 -04:00
|
|
|
query = _.template(template, templateData, this.templateSettings);
|
2014-08-27 16:29:48 +02:00
|
|
|
query = timeSrv.applyTemplateToTarget(query);
|
2014-06-06 10:56:23 +02:00
|
|
|
|
2014-06-14 14:38:14 +02:00
|
|
|
if (target.groupby_field_add) {
|
|
|
|
|
groupByField = target.groupby_field;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-28 01:13:11 -04:00
|
|
|
target.query = query;
|
|
|
|
|
}
|
2014-02-27 21:46:06 +01:00
|
|
|
|
2014-07-15 16:46:17 +02:00
|
|
|
if (target.alias) {
|
|
|
|
|
alias = filterSrv.applyTemplateToTarget(target.alias);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-14 14:38:14 +02:00
|
|
|
var handleResponse = _.partial(handleInfluxQueryResponse, alias, groupByField);
|
2014-07-30 15:32:15 +02:00
|
|
|
return this._seriesQuery(query).then(handleResponse);
|
2014-02-27 21:46:06 +01:00
|
|
|
|
2014-03-02 10:41:16 +01:00
|
|
|
}, this);
|
2014-02-27 21:46:06 +01:00
|
|
|
|
2014-03-02 10:41:16 +01:00
|
|
|
return $q.all(promises).then(function(results) {
|
|
|
|
|
return { data: _.flatten(results) };
|
2014-02-27 21:46:06 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2014-07-16 18:47:20 +02:00
|
|
|
InfluxDatasource.prototype.annotationQuery = function(annotation, filterSrv, rangeUnparsed) {
|
|
|
|
|
var timeFilter = getTimeFilter({ range: rangeUnparsed });
|
2014-07-17 10:24:30 +02:00
|
|
|
var query = _.template(annotation.query, { timeFilter: timeFilter }, this.templateSettings);
|
|
|
|
|
|
2014-07-30 15:32:15 +02:00
|
|
|
return this._seriesQuery(query).then(function(results) {
|
2014-07-17 10:24:30 +02:00
|
|
|
return new InfluxSeries({ seriesList: results, annotation: annotation }).getAnnotations();
|
|
|
|
|
});
|
2014-07-16 18:47:20 +02:00
|
|
|
};
|
2014-03-05 12:43:44 +01:00
|
|
|
InfluxDatasource.prototype.listColumns = function(seriesName) {
|
2014-08-11 12:11:24 +02:00
|
|
|
|
2014-07-30 15:32:15 +02:00
|
|
|
return this._seriesQuery('select * from /' + seriesName + '/ limit 1').then(function(data) {
|
2014-03-28 01:13:11 -04:00
|
|
|
if (!data) {
|
2014-03-05 12:43:44 +01:00
|
|
|
return [];
|
|
|
|
|
}
|
2014-06-22 11:09:27 +02:00
|
|
|
return data[0].columns;
|
2014-03-05 12:43:44 +01:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2014-03-03 08:39:05 +01:00
|
|
|
InfluxDatasource.prototype.listSeries = function() {
|
2014-07-30 15:32:15 +02:00
|
|
|
return this._seriesQuery('list series').then(function(data) {
|
2014-07-25 12:14:15 +02:00
|
|
|
if (!data || data.length === 0) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
// influxdb >= 1.8
|
2014-07-30 15:32:15 +02:00
|
|
|
if (data[0].points.length > 0) {
|
2014-07-25 12:14:15 +02:00
|
|
|
return _.map(data[0].points, function(point) {
|
|
|
|
|
return point[1];
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else { // influxdb <= 1.7
|
|
|
|
|
return _.map(data, function(series) {
|
|
|
|
|
return series.name; // influxdb < 1.7
|
|
|
|
|
});
|
|
|
|
|
}
|
2014-03-03 08:39:05 +01:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2014-06-03 21:23:42 +02:00
|
|
|
InfluxDatasource.prototype.metricFindQuery = function (filterSrv, query) {
|
2014-05-01 00:43:34 +02:00
|
|
|
var interpolated;
|
|
|
|
|
try {
|
2014-06-03 21:23:42 +02:00
|
|
|
interpolated = filterSrv.applyTemplateToTarget(query);
|
2014-05-01 00:43:34 +02:00
|
|
|
}
|
2014-06-07 06:38:33 +02:00
|
|
|
catch (err) {
|
2014-05-01 00:43:34 +02:00
|
|
|
return $q.reject(err);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-30 15:32:15 +02:00
|
|
|
return this._seriesQuery(interpolated)
|
2014-05-01 00:43:34 +02:00
|
|
|
.then(function (results) {
|
|
|
|
|
return _.map(results[0].points, function (metric) {
|
|
|
|
|
return {
|
|
|
|
|
text: metric[1],
|
|
|
|
|
expandable: false
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2014-03-28 01:13:11 -04:00
|
|
|
function retry(deferred, callback, delay) {
|
|
|
|
|
return callback().then(undefined, function(reason) {
|
2014-06-02 13:15:10 -07:00
|
|
|
if (reason.status !== 0 || reason.status >= 300) {
|
2014-08-11 12:11:24 +02:00
|
|
|
reason.message = 'InfluxDB Error: <br/>' + reason.data;
|
2014-03-28 01:13:11 -04:00
|
|
|
deferred.reject(reason);
|
|
|
|
|
}
|
2014-06-02 13:15:10 -07:00
|
|
|
else {
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
return retry(deferred, callback, Math.min(delay * 2, 30000));
|
|
|
|
|
}, delay);
|
2014-03-28 01:13:11 -04:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-30 15:32:15 +02:00
|
|
|
InfluxDatasource.prototype._seriesQuery = function(query) {
|
|
|
|
|
return this._influxRequest('GET', '/series', {
|
|
|
|
|
q: query,
|
|
|
|
|
time_precision: 's',
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
InfluxDatasource.prototype._influxRequest = function(method, url, data) {
|
2014-03-28 01:13:11 -04:00
|
|
|
var _this = this;
|
|
|
|
|
var deferred = $q.defer();
|
2014-02-27 21:46:06 +01:00
|
|
|
|
2014-03-28 01:13:11 -04:00
|
|
|
retry(deferred, function() {
|
|
|
|
|
var currentUrl = _this.urls.shift();
|
|
|
|
|
_this.urls.push(currentUrl);
|
|
|
|
|
|
|
|
|
|
var params = {
|
|
|
|
|
u: _this.username,
|
|
|
|
|
p: _this.password,
|
|
|
|
|
};
|
|
|
|
|
|
2014-07-30 15:32:15 +02:00
|
|
|
if (method === 'GET') {
|
|
|
|
|
_.extend(params, data);
|
|
|
|
|
data = null;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-28 01:13:11 -04:00
|
|
|
var options = {
|
2014-07-30 15:32:15 +02:00
|
|
|
method: method,
|
|
|
|
|
url: currentUrl + url,
|
2014-03-28 01:13:11 -04:00
|
|
|
params: params,
|
2014-08-10 14:03:10 +02:00
|
|
|
data: data,
|
|
|
|
|
inspect: { type: 'influxdb' },
|
2014-03-28 01:13:11 -04:00
|
|
|
};
|
|
|
|
|
|
2014-08-11 13:39:02 +02:00
|
|
|
return $http(options).success(function (data) {
|
2014-03-28 01:13:11 -04:00
|
|
|
deferred.resolve(data);
|
|
|
|
|
});
|
|
|
|
|
}, 10);
|
2014-02-27 21:46:06 +01:00
|
|
|
|
2014-03-28 01:13:11 -04:00
|
|
|
return deferred.promise;
|
2014-07-30 15:32:15 +02:00
|
|
|
};
|
|
|
|
|
|
2014-08-03 12:07:50 +02:00
|
|
|
InfluxDatasource.prototype.saveDashboard = function(dashboard) {
|
|
|
|
|
var tags = dashboard.tags.join(',');
|
|
|
|
|
var title = dashboard.title;
|
|
|
|
|
var temp = dashboard.temp;
|
|
|
|
|
if (temp) { delete dashboard.temp; }
|
2014-07-30 15:32:15 +02:00
|
|
|
|
|
|
|
|
var data = [{
|
2014-07-31 10:36:45 +02:00
|
|
|
name: 'grafana.dashboard_' + btoa(title),
|
2014-07-30 15:32:15 +02:00
|
|
|
columns: ['time', 'sequence_number', 'title', 'tags', 'dashboard'],
|
2014-08-03 12:07:50 +02:00
|
|
|
points: [[1000000000000, 1, title, tags, angular.toJson(dashboard)]]
|
2014-07-30 15:32:15 +02:00
|
|
|
}];
|
|
|
|
|
|
2014-08-03 12:07:50 +02:00
|
|
|
if (temp) {
|
|
|
|
|
return this._saveDashboardTemp(data, title);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return this._influxRequest('POST', '/series', data).then(function() {
|
|
|
|
|
return { title: title, url: '/dashboard/db/' + title };
|
|
|
|
|
}, function(err) {
|
|
|
|
|
throw 'Failed to save dashboard to InfluxDB: ' + err.data;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
InfluxDatasource.prototype._saveDashboardTemp = function(data, title) {
|
2014-08-03 12:20:42 +02:00
|
|
|
data[0].name = 'grafana.temp_dashboard_' + btoa(title);
|
2014-08-03 12:07:50 +02:00
|
|
|
data[0].columns.push('expires');
|
|
|
|
|
data[0].points[0].push(this._getTempDashboardExpiresDate());
|
|
|
|
|
|
2014-07-30 15:32:15 +02:00
|
|
|
return this._influxRequest('POST', '/series', data).then(function() {
|
2014-08-03 12:07:50 +02:00
|
|
|
var baseUrl = window.location.href.replace(window.location.hash,'');
|
|
|
|
|
var url = baseUrl + "#dashboard/temp/" + title;
|
|
|
|
|
return { title: title, url: url };
|
2014-07-30 15:32:15 +02:00
|
|
|
}, function(err) {
|
2014-08-03 12:07:50 +02:00
|
|
|
throw 'Failed to save shared dashboard to InfluxDB: ' + err.data;
|
2014-07-30 15:32:15 +02:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2014-08-03 12:07:50 +02:00
|
|
|
InfluxDatasource.prototype._getTempDashboardExpiresDate = function() {
|
|
|
|
|
var ttlLength = this.saveTempTTL.substring(0, this.saveTempTTL.length - 1);
|
|
|
|
|
var ttlTerm = this.saveTempTTL.substring(this.saveTempTTL.length - 1, this.saveTempTTL.length).toLowerCase();
|
2014-07-31 12:36:32 -07:00
|
|
|
var expires = Date.now();
|
|
|
|
|
switch(ttlTerm) {
|
|
|
|
|
case "m":
|
|
|
|
|
expires += ttlLength * 60000;
|
|
|
|
|
break;
|
|
|
|
|
case "d":
|
|
|
|
|
expires += ttlLength * 86400000;
|
|
|
|
|
break;
|
|
|
|
|
case "w":
|
|
|
|
|
expires += ttlLength * 604800000;
|
2014-07-31 13:48:28 -07:00
|
|
|
break;
|
2014-07-31 12:36:32 -07:00
|
|
|
default:
|
2014-07-31 13:45:17 -07:00
|
|
|
throw "Unknown ttl duration format";
|
2014-07-31 12:36:32 -07:00
|
|
|
}
|
2014-08-03 12:07:50 +02:00
|
|
|
return expires;
|
2014-07-31 12:36:32 -07:00
|
|
|
};
|
2014-08-03 12:07:50 +02:00
|
|
|
|
|
|
|
|
InfluxDatasource.prototype.getDashboard = function(id, isTemp) {
|
2014-07-31 12:36:32 -07:00
|
|
|
var queryString = 'select dashboard from "grafana.dashboard_' + btoa(id) + '"';
|
2014-08-03 12:07:50 +02:00
|
|
|
|
|
|
|
|
if (isTemp) {
|
2014-08-03 12:20:42 +02:00
|
|
|
queryString = 'select dashboard from "grafana.temp_dashboard_' + btoa(id) + '"';
|
2014-07-31 12:36:32 -07:00
|
|
|
}
|
2014-08-03 12:07:50 +02:00
|
|
|
|
2014-07-31 12:36:32 -07:00
|
|
|
return this._seriesQuery(queryString).then(function(results) {
|
2014-07-30 15:32:15 +02:00
|
|
|
if (!results || !results.length) {
|
|
|
|
|
throw "Dashboard not found";
|
|
|
|
|
}
|
2014-08-03 12:07:50 +02:00
|
|
|
|
2014-07-30 15:32:15 +02:00
|
|
|
var dashCol = _.indexOf(results[0].columns, 'dashboard');
|
|
|
|
|
var dashJson = results[0].points[0][dashCol];
|
2014-08-03 12:07:50 +02:00
|
|
|
|
2014-07-30 15:32:15 +02:00
|
|
|
return angular.fromJson(dashJson);
|
|
|
|
|
}, function(err) {
|
|
|
|
|
return "Could not load dashboard, " + err.data;
|
|
|
|
|
});
|
2014-07-31 10:36:45 +02:00
|
|
|
};
|
|
|
|
|
|
2014-07-31 12:38:46 +02:00
|
|
|
InfluxDatasource.prototype.deleteDashboard = function(id) {
|
|
|
|
|
return this._seriesQuery('drop series "grafana.dashboard_' + btoa(id) + '"').then(function(results) {
|
|
|
|
|
if (!results) {
|
|
|
|
|
throw "Could not delete dashboard";
|
|
|
|
|
}
|
|
|
|
|
return id;
|
|
|
|
|
}, function(err) {
|
|
|
|
|
return "Could not delete dashboard, " + err.data;
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2014-07-31 10:36:45 +02:00
|
|
|
InfluxDatasource.prototype.searchDashboards = function(queryString) {
|
|
|
|
|
var influxQuery = 'select title, tags from /grafana.dashboard_.*/ where ';
|
|
|
|
|
|
|
|
|
|
var tagsOnly = queryString.indexOf('tags!:') === 0;
|
|
|
|
|
if (tagsOnly) {
|
|
|
|
|
var tagsQuery = queryString.substring(6, queryString.length);
|
|
|
|
|
influxQuery = influxQuery + 'tags =~ /.*' + tagsQuery + '.*/i';
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
var titleOnly = queryString.indexOf('title:') === 0;
|
|
|
|
|
if (titleOnly) {
|
|
|
|
|
var titleQuery = queryString.substring(6, queryString.length);
|
|
|
|
|
influxQuery = influxQuery + ' title =~ /.*' + titleQuery + '.*/i';
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
influxQuery = influxQuery + '(tags =~ /.*' + queryString + '.*/i or title =~ /.*' + queryString + '.*/i)';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return this._seriesQuery(influxQuery).then(function(results) {
|
2014-07-31 10:54:36 +02:00
|
|
|
var hits = { dashboards: [], tags: [], tagsOnly: false };
|
|
|
|
|
|
2014-07-31 10:36:45 +02:00
|
|
|
if (!results || !results.length) {
|
2014-07-31 10:54:36 +02:00
|
|
|
return hits;
|
2014-07-31 10:36:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var dashCol = _.indexOf(results[0].columns, 'title');
|
|
|
|
|
var tagsCol = _.indexOf(results[0].columns, 'tags');
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < results.length; i++) {
|
|
|
|
|
var hit = {
|
|
|
|
|
id: results[i].points[0][dashCol],
|
2014-08-21 21:59:23 +02:00
|
|
|
title: results[i].points[0][dashCol],
|
2014-07-31 10:36:45 +02:00
|
|
|
tags: results[i].points[0][tagsCol].split(",")
|
|
|
|
|
};
|
|
|
|
|
hit.tags = hit.tags[0] ? hit.tags : [];
|
2014-07-31 10:54:36 +02:00
|
|
|
hits.dashboards.push(hit);
|
2014-07-31 10:36:45 +02:00
|
|
|
}
|
2014-07-31 10:54:36 +02:00
|
|
|
return hits;
|
2014-07-31 10:36:45 +02:00
|
|
|
});
|
2014-02-27 21:46:06 +01:00
|
|
|
};
|
|
|
|
|
|
2014-07-01 15:55:56 +02:00
|
|
|
function handleInfluxQueryResponse(alias, groupByField, seriesList) {
|
|
|
|
|
var influxSeries = new InfluxSeries({
|
|
|
|
|
seriesList: seriesList,
|
|
|
|
|
alias: alias,
|
|
|
|
|
groupByField: groupByField
|
2014-03-02 10:41:16 +01:00
|
|
|
});
|
|
|
|
|
|
2014-07-01 15:55:56 +02:00
|
|
|
return influxSeries.getTimeSeries();
|
2014-03-02 10:41:16 +01:00
|
|
|
}
|
|
|
|
|
|
2014-03-01 12:02:55 +01:00
|
|
|
function getTimeFilter(options) {
|
2014-03-02 10:41:16 +01:00
|
|
|
var from = getInfluxTime(options.range.from);
|
|
|
|
|
var until = getInfluxTime(options.range.to);
|
2014-03-01 15:38:00 +01:00
|
|
|
|
2014-03-02 10:41:16 +01:00
|
|
|
if (until === 'now()') {
|
|
|
|
|
return 'time > now() - ' + from;
|
2014-03-01 15:38:00 +01:00
|
|
|
}
|
|
|
|
|
|
2014-03-02 10:41:16 +01:00
|
|
|
return 'time > ' + from + ' and time < ' + until;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getInfluxTime(date) {
|
|
|
|
|
if (_.isString(date)) {
|
|
|
|
|
if (date === 'now') {
|
|
|
|
|
return 'now()';
|
|
|
|
|
}
|
|
|
|
|
else if (date.indexOf('now') >= 0) {
|
|
|
|
|
return date.substring(4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
date = kbn.parseDate(date);
|
2014-03-01 15:38:00 +01:00
|
|
|
}
|
2014-03-02 10:41:16 +01:00
|
|
|
|
|
|
|
|
return to_utc_epoch_seconds(date);
|
2014-03-01 15:38:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function to_utc_epoch_seconds(date) {
|
|
|
|
|
return (date.getTime() / 1000).toFixed(0) + 's';
|
2014-03-01 12:02:55 +01:00
|
|
|
}
|
|
|
|
|
|
2014-02-27 21:46:06 +01:00
|
|
|
return InfluxDatasource;
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|