From 36f56f3695b454e64d14148b029b3176779f37e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Sat, 15 Feb 2014 13:46:36 +0100 Subject: [PATCH] Closes #35, grafana now supports multiple graphite backends. Check config.sample for how to setup. In the general tab of the graphite panel you can change datasource --- src/app/components/settings.js | 24 ++- src/app/controllers/graphiteImport.js | 6 +- src/app/controllers/graphiteTarget.js | 6 +- src/app/panels/filtering/module.js | 4 +- src/app/panels/graphite/module.html | 10 ++ src/app/panels/graphite/module.js | 19 ++- src/app/services/all.js | 2 +- src/app/services/annotationsSrv.js | 4 +- src/app/services/dashboard.js | 1 - src/app/services/datasourceSrv.js | 34 ++++ .../services/graphite/graphiteDatasource.js | 150 ++++++++++++++++ src/app/services/graphite/graphiteSrv.js | 161 ------------------ src/config.sample.js | 9 + 13 files changed, 252 insertions(+), 178 deletions(-) create mode 100644 src/app/services/datasourceSrv.js create mode 100644 src/app/services/graphite/graphiteDatasource.js delete mode 100644 src/app/services/graphite/graphiteSrv.js diff --git a/src/app/components/settings.js b/src/app/components/settings.js index b483007d25e..62ba18826a9 100644 --- a/src/app/components/settings.js +++ b/src/app/components/settings.js @@ -14,7 +14,12 @@ function (_, crypto) { */ var defaults = { elasticsearch : "http://"+window.location.hostname+":9200", - graphiteUrl : "http://"+window.location.hostname+":8080", + datasources : { + default: { + url: "http://"+window.location.hostname+":8080", + default: true + } + }, panel_names : [], default_route : '/dashboard/file/default.json', grafana_index : 'grafana-dash', @@ -40,7 +45,22 @@ function (_, crypto) { } }; - settings.graphiteBasicAuth = basicAuth(settings.graphiteUrl); + if (options.graphiteUrl) { + settings.datasources = { + graphite: { + name: 'default', + url: options.graphiteUrl, + default: true, + basicAuth: basicAuth(options.graphiteUrl) + } + }; + } + else { + _.each(_.values(settings.datasources), function(source) { + source.basicAuth = basicAuth(source.url); + }); + } + settings.elasticsearchBasicAuth = basicAuth(settings.elasticsearch); return settings; }; diff --git a/src/app/controllers/graphiteImport.js b/src/app/controllers/graphiteImport.js index 87990bf2671..10f6e4d0593 100644 --- a/src/app/controllers/graphiteImport.js +++ b/src/app/controllers/graphiteImport.js @@ -8,7 +8,7 @@ function (angular, app, _) { var module = angular.module('kibana.controllers'); - module.controller('GraphiteImportCtrl', function($scope, $rootScope, $timeout, graphiteSrv, dashboard) { + module.controller('GraphiteImportCtrl', function($scope, $rootScope, $timeout, datasourceSrv, dashboard) { $scope.init = function() { console.log('hej!'); @@ -17,7 +17,7 @@ function (angular, app, _) { $scope.listAll = function(query) { delete $scope.error; - graphiteSrv.listDashboards(query) + datasourceSrv.default.listDashboards(query) .then(function(results) { $scope.dashboards = results; }) @@ -29,7 +29,7 @@ function (angular, app, _) { $scope.import = function(dashName) { delete $scope.error; - graphiteSrv.loadDashboard(dashName) + datasourceSrv.default.loadDashboard(dashName) .then(function(results) { if (!results.data || !results.data.state) { throw { message: 'no dashboard state received from graphite' }; diff --git a/src/app/controllers/graphiteTarget.js b/src/app/controllers/graphiteTarget.js index 43620c7bd87..8ec5bde50ac 100644 --- a/src/app/controllers/graphiteTarget.js +++ b/src/app/controllers/graphiteTarget.js @@ -10,7 +10,7 @@ function (angular, _, config, gfunc, Parser) { var module = angular.module('kibana.controllers'); - module.controller('GraphiteTargetCtrl', function($scope, $http, filterSrv, graphiteSrv) { + module.controller('GraphiteTargetCtrl', function($scope, $http, filterSrv) { $scope.init = function() { $scope.funcCategories = gfunc.getCategories(); @@ -121,7 +121,7 @@ function (angular, _, config, gfunc, Parser) { } var path = getSegmentPathUpTo(fromIndex + 1); - return graphiteSrv.metricFindQuery(path) + return $scope.datasource.metricFindQuery(path) .then(function(segments) { if (segments.length === 0) { $scope.segments = $scope.segments.splice(0, fromIndex); @@ -158,7 +158,7 @@ function (angular, _, config, gfunc, Parser) { var query = index === 0 ? '*' : getSegmentPathUpTo(index) + '.*'; - return graphiteSrv.metricFindQuery(query) + return $scope.datasource.metricFindQuery(query) .then(function(segments) { _.each(segments, function(segment) { segment.html = segment.val = segment.text; diff --git a/src/app/panels/filtering/module.js b/src/app/panels/filtering/module.js index f0d69040029..9fc84471085 100644 --- a/src/app/panels/filtering/module.js +++ b/src/app/panels/filtering/module.js @@ -14,7 +14,7 @@ function (angular, app, _) { var module = angular.module('kibana.panels.filtering', []); app.useModule(module); - module.controller('filtering', function($scope, filterSrv, graphiteSrv, $rootScope, dashboard) { + module.controller('filtering', function($scope, filterSrv, datasourceSrv, $rootScope, dashboard) { $scope.panelMeta = { status : "Stable", @@ -35,7 +35,7 @@ function (angular, app, _) { }; $scope.applyFilter = function(filter) { - graphiteSrv.metricFindQuery(filter.query) + datasourceSrv.default.metricFindQuery(filter.query) .then(function (results) { filter.editing=undefined; filter.options = _.map(results, function(node) { diff --git a/src/app/panels/graphite/module.html b/src/app/panels/graphite/module.html index 0812e28b678..8b14f02c220 100644 --- a/src/app/panels/graphite/module.html +++ b/src/app/panels/graphite/module.html @@ -27,10 +27,20 @@
+ +
+
+
+ +