mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(plugins): upgraded influxdb to new data source plugin model
This commit is contained in:
parent
15546dd84e
commit
b76449d151
@ -4,7 +4,6 @@ define([
|
|||||||
'app/core/utils/datemath',
|
'app/core/utils/datemath',
|
||||||
'./influx_series',
|
'./influx_series',
|
||||||
'./influx_query',
|
'./influx_query',
|
||||||
'./directives',
|
|
||||||
'./query_ctrl',
|
'./query_ctrl',
|
||||||
],
|
],
|
||||||
function (angular, _, dateMath, InfluxSeries, InfluxQuery) {
|
function (angular, _, dateMath, InfluxSeries, InfluxQuery) {
|
||||||
@ -12,27 +11,22 @@ function (angular, _, dateMath, InfluxSeries, InfluxQuery) {
|
|||||||
|
|
||||||
InfluxQuery = InfluxQuery.default;
|
InfluxQuery = InfluxQuery.default;
|
||||||
|
|
||||||
var module = angular.module('grafana.services');
|
function InfluxDatasource(instanceSettings, $q, backendSrv, templateSrv) {
|
||||||
|
this.type = 'influxdb';
|
||||||
|
this.urls = _.map(instanceSettings.url.split(','), function(url) {
|
||||||
|
return url.trim();
|
||||||
|
});
|
||||||
|
|
||||||
module.factory('InfluxDatasource', function($q, backendSrv, templateSrv) {
|
this.username = instanceSettings.username;
|
||||||
|
this.password = instanceSettings.password;
|
||||||
|
this.name = instanceSettings.name;
|
||||||
|
this.database = instanceSettings.database;
|
||||||
|
this.basicAuth = instanceSettings.basicAuth;
|
||||||
|
|
||||||
function InfluxDatasource(datasource) {
|
this.supportAnnotations = true;
|
||||||
this.type = 'influxdb';
|
this.supportMetrics = true;
|
||||||
this.urls = _.map(datasource.url.split(','), function(url) {
|
|
||||||
return url.trim();
|
|
||||||
});
|
|
||||||
|
|
||||||
this.username = datasource.username;
|
this.query = function(options) {
|
||||||
this.password = datasource.password;
|
|
||||||
this.name = datasource.name;
|
|
||||||
this.database = datasource.database;
|
|
||||||
this.basicAuth = datasource.basicAuth;
|
|
||||||
|
|
||||||
this.supportAnnotations = true;
|
|
||||||
this.supportMetrics = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
InfluxDatasource.prototype.query = function(options) {
|
|
||||||
var timeFilter = getTimeFilter(options);
|
var timeFilter = getTimeFilter(options);
|
||||||
var queryTargets = [];
|
var queryTargets = [];
|
||||||
var i, y;
|
var i, y;
|
||||||
@ -93,7 +87,7 @@ function (angular, _, dateMath, InfluxSeries, InfluxQuery) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
InfluxDatasource.prototype.annotationQuery = function(options) {
|
this.annotationQuery = function(options) {
|
||||||
var timeFilter = getTimeFilter({rangeRaw: options.rangeRaw});
|
var timeFilter = getTimeFilter({rangeRaw: options.rangeRaw});
|
||||||
var query = options.annotation.query.replace('$timeFilter', timeFilter);
|
var query = options.annotation.query.replace('$timeFilter', timeFilter);
|
||||||
query = templateSrv.replace(query);
|
query = templateSrv.replace(query);
|
||||||
@ -106,7 +100,7 @@ function (angular, _, dateMath, InfluxSeries, InfluxQuery) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
InfluxDatasource.prototype.metricFindQuery = function (query) {
|
this.metricFindQuery = function (query) {
|
||||||
var interpolated;
|
var interpolated;
|
||||||
try {
|
try {
|
||||||
interpolated = templateSrv.replace(query);
|
interpolated = templateSrv.replace(query);
|
||||||
@ -133,17 +127,17 @@ function (angular, _, dateMath, InfluxSeries, InfluxQuery) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
InfluxDatasource.prototype._seriesQuery = function(query) {
|
this._seriesQuery = function(query) {
|
||||||
return this._influxRequest('GET', '/query', {q: query, epoch: 'ms'});
|
return this._influxRequest('GET', '/query', {q: query, epoch: 'ms'});
|
||||||
};
|
};
|
||||||
|
|
||||||
InfluxDatasource.prototype.testDatasource = function() {
|
this.testDatasource = function() {
|
||||||
return this.metricFindQuery('SHOW MEASUREMENTS LIMIT 1').then(function () {
|
return this.metricFindQuery('SHOW MEASUREMENTS LIMIT 1').then(function () {
|
||||||
return { status: "success", message: "Data source is working", title: "Success" };
|
return { status: "success", message: "Data source is working", title: "Success" };
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
InfluxDatasource.prototype._influxRequest = function(method, url, data) {
|
this._influxRequest = function(method, url, data) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var currentUrl = self.urls.shift();
|
var currentUrl = self.urls.shift();
|
||||||
@ -219,9 +213,8 @@ function (angular, _, dateMath, InfluxSeries, InfluxQuery) {
|
|||||||
}
|
}
|
||||||
return (date.valueOf() / 1000).toFixed(0) + 's';
|
return (date.valueOf() / 1000).toFixed(0) + 's';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return InfluxDatasource;
|
return InfluxDatasource;
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
define([
|
define([
|
||||||
'angular',
|
'angular',
|
||||||
|
'./datasource',
|
||||||
],
|
],
|
||||||
function (angular) {
|
function (angular, InfluxDatasource) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var module = angular.module('grafana.directives');
|
var module = angular.module('grafana.directives');
|
||||||
@ -18,4 +19,11 @@ function (angular) {
|
|||||||
return {templateUrl: 'app/plugins/datasource/influxdb/partials/annotations.editor.html'};
|
return {templateUrl: 'app/plugins/datasource/influxdb/partials/annotations.editor.html'};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
module.directive('datasourceCustomSettingsViewInfluxdb', function() {
|
||||||
|
return {templateUrl: 'app/plugins/datasource/influxdb/partials/config.html'};
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
Datasource: InfluxDatasource
|
||||||
|
};
|
||||||
});
|
});
|
@ -3,13 +3,7 @@
|
|||||||
"name": "InfluxDB 0.9.x",
|
"name": "InfluxDB 0.9.x",
|
||||||
"id": "influxdb",
|
"id": "influxdb",
|
||||||
|
|
||||||
"serviceName": "InfluxDatasource",
|
"module": "app/plugins/datasource/influxdb/module",
|
||||||
|
|
||||||
"module": "app/plugins/datasource/influxdb/datasource",
|
|
||||||
|
|
||||||
"partials": {
|
|
||||||
"config": "app/plugins/datasource/influxdb/partials/config.html"
|
|
||||||
},
|
|
||||||
|
|
||||||
"defaultMatchFormat": "regex values",
|
"defaultMatchFormat": "regex values",
|
||||||
"metrics": true,
|
"metrics": true,
|
||||||
|
Loading…
Reference in New Issue
Block a user