From e3f56f2645683fd3345ce8e7800bc45411b0a981 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 27 Feb 2014 21:46:06 +0100 Subject: [PATCH] refactoring of graphite panel to be more datasource agnostic, start of experimental influxdb support --- src/app/dashboards/default.json | 3 +- src/app/directives/grafanaGraph.js | 2 +- src/app/directives/kibanaPanel.js | 3 +- src/app/panels/graphite/module.html | 28 +++---- src/app/panels/graphite/module.js | 17 ++-- .../{panels => partials}/graphite/editor.html | 3 +- .../graphite/funcEditor.html | 0 src/app/partials/influxdb/editor.html | 1 + src/app/partials/paneladd.html | 12 +-- src/app/partials/panelgeneral.html | 40 +++++----- src/app/services/all.js | 1 - src/app/services/datasourceSrv.js | 19 +++-- .../services/graphite/graphiteDatasource.js | 1 + .../services/influxdb/influxdbDatasource.js | 77 +++++++++++++++++++ 14 files changed, 140 insertions(+), 67 deletions(-) rename src/app/{panels => partials}/graphite/editor.html (97%) rename src/app/{panels => partials}/graphite/funcEditor.html (100%) create mode 100644 src/app/partials/influxdb/editor.html create mode 100644 src/app/services/influxdb/influxdbDatasource.js diff --git a/src/app/dashboards/default.json b/src/app/dashboards/default.json index ff25b326410..41a5fd76a49 100644 --- a/src/app/dashboards/default.json +++ b/src/app/dashboards/default.json @@ -69,8 +69,7 @@ "nullPointMode": "connected", "steppedLine": false, "tooltip": { - "value_type": "cumulative", - "query_as_alias": true + "value_type": "cumulative" }, "targets": [ { diff --git a/src/app/directives/grafanaGraph.js b/src/app/directives/grafanaGraph.js index 545ab351f5f..44e645ea6d2 100644 --- a/src/app/directives/grafanaGraph.js +++ b/src/app/directives/grafanaGraph.js @@ -289,7 +289,7 @@ function (angular, $, kbn, moment, _) { seriesInfo = item.series.info; format = scope.panel.y_formats[seriesInfo.yaxis - 1]; - if (seriesInfo.alias || scope.panel.tooltip.query_as_alias) { + if (seriesInfo.alias) { group = '' + '' + ' ' + (seriesInfo.alias || seriesInfo.query)+ diff --git a/src/app/directives/kibanaPanel.js b/src/app/directives/kibanaPanel.js index 1afc23ec00d..719889b0b7f 100644 --- a/src/app/directives/kibanaPanel.js +++ b/src/app/directives/kibanaPanel.js @@ -88,8 +88,7 @@ function (angular, $) { var nameAsPath = name.replace(".", "/"); $scope.require([ 'jquery', - 'text!panels/'+nameAsPath+'/module.html', - 'text!panels/'+nameAsPath+'/editor.html' + 'text!panels/'+nameAsPath+'/module.html' ], function ($, moduleTemplate) { var $module = $(moduleTemplate); // top level controllers diff --git a/src/app/panels/graphite/module.html b/src/app/panels/graphite/module.html index 3ec2f846b99..6f2bdd1f759 100644 --- a/src/app/panels/graphite/module.html +++ b/src/app/panels/graphite/module.html @@ -27,27 +27,23 @@
-
-
-
+
+
+
- -
-
-
- +
\ No newline at end of file diff --git a/src/app/panels/graphite/module.js b/src/app/panels/graphite/module.js index 6ef1a3b5cae..abbd382f02c 100644 --- a/src/app/panels/graphite/module.js +++ b/src/app/panels/graphite/module.js @@ -38,15 +38,15 @@ function (angular, app, $, _, kbn, moment, timeSeries) { $scope.panelMeta = { modals : [], + editorTabs: [], - editorTabs : [ + fullEditorTabs : [ { title: 'General', src:'app/partials/panelgeneral.html' }, { - title:'Targets', - src:'app/panels/graphite/editor.html' + title: 'Metrics', }, { title:'Axes & Grid', @@ -80,7 +80,7 @@ function (angular, app, $, _, kbn, moment, timeSeries) { ], status : "Unstable", - description : "Graphite graphing panel

" + description : "Graphs panel" }; // Set and populate defaults @@ -224,21 +224,18 @@ function (angular, app, $, _, kbn, moment, timeSeries) { $scope.fullscreen = false; $scope.options = false; $scope.editor = {index: 1}; - $scope.editorTabs = _.pluck($scope.panelMeta.editorTabs,'title'); + $scope.editorTabs = _.pluck($scope.panelMeta.fullEditorTabs,'title'); $scope.hiddenSeries = {}; $scope.datasources = datasourceSrv.listOptions(); - $scope.datasource = datasourceSrv.get($scope.panel.datasource); - - // Always show the query if an alias isn't set. Users can set an alias if the query is too - // long - $scope.panel.tooltip.query_as_alias = true; + $scope.datasourceChanged(); $scope.get_data(); }; $scope.datasourceChanged = function() { $scope.datasource = datasourceSrv.get($scope.panel.datasource); + $scope.panelMeta.fullEditorTabs[1].src = $scope.datasource.editorSrc; $scope.get_data(); }; diff --git a/src/app/panels/graphite/editor.html b/src/app/partials/graphite/editor.html similarity index 97% rename from src/app/panels/graphite/editor.html rename to src/app/partials/graphite/editor.html index 32fb30fb41f..4385f421377 100644 --- a/src/app/panels/graphite/editor.html +++ b/src/app/partials/graphite/editor.html @@ -1,3 +1,4 @@ +
  • - + {{func.text}}
  • diff --git a/src/app/panels/graphite/funcEditor.html b/src/app/partials/graphite/funcEditor.html similarity index 100% rename from src/app/panels/graphite/funcEditor.html rename to src/app/partials/graphite/funcEditor.html diff --git a/src/app/partials/influxdb/editor.html b/src/app/partials/influxdb/editor.html new file mode 100644 index 00000000000..9daaaec51e8 --- /dev/null +++ b/src/app/partials/influxdb/editor.html @@ -0,0 +1 @@ +
    InfluxDB
    \ No newline at end of file diff --git a/src/app/partials/paneladd.html b/src/app/partials/paneladd.html index 5b780fb2e03..f902bbce561 100644 --- a/src/app/partials/paneladd.html +++ b/src/app/partials/paneladd.html @@ -1,6 +1,6 @@ -
    -
    -
    -
    {{tab.title}}
    -
    -
    \ No newline at end of file +
    +
    +
    +
    {{tab.title}}
    +
    +
    \ No newline at end of file diff --git a/src/app/partials/panelgeneral.html b/src/app/partials/panelgeneral.html index f8da4943e70..1d44f0a8538 100644 --- a/src/app/partials/panelgeneral.html +++ b/src/app/partials/panelgeneral.html @@ -1,24 +1,20 @@ -
    -
    - {{panelMeta.status}} // +
    +
    +
    General options
    +
    + +
    +
    + +
    +
    + +
    +
    + +
    -
    -
    -
    - -
    -
    - -
    -
    - -
    -
    - - -
    -
    -
    \ No newline at end of file +
    \ No newline at end of file diff --git a/src/app/services/all.js b/src/app/services/all.js index cee5cc16a02..6c0164a027e 100644 --- a/src/app/services/all.js +++ b/src/app/services/all.js @@ -7,6 +7,5 @@ define([ './datasourceSrv', './keyboardManager', './annotationsSrv', - './graphite/graphiteDatasource', ], function () {}); \ No newline at end of file diff --git a/src/app/services/datasourceSrv.js b/src/app/services/datasourceSrv.js index d82c7b20339..1bc4c4407a6 100644 --- a/src/app/services/datasourceSrv.js +++ b/src/app/services/datasourceSrv.js @@ -1,25 +1,32 @@ define([ 'angular', 'underscore', - 'config' + 'config', + './graphite/graphiteDatasource', + './influxdb/influxdbDatasource', ], function (angular, _, config) { 'use strict'; var module = angular.module('kibana.services'); - module.service('datasourceSrv', function($q, filterSrv, $http, GraphiteDatasource) { + module.service('datasourceSrv', function($q, filterSrv, $http, GraphiteDatasource, InfluxDatasource) { var defaultDatasource = _.findWhere(_.values(config.datasources), { default: true } ); this.default = new GraphiteDatasource(defaultDatasource); this.get = function(name) { - if (!name) { - return this.default; - } + if (!name) { return this.default; } - return new GraphiteDatasource(config.datasources[name]); + var ds = config.datasources[name]; + + switch(ds.type) { + case 'graphite': + return new GraphiteDatasource(ds); + case 'influxdb': + return new InfluxDatasource(ds); + } }; this.listOptions = function() { diff --git a/src/app/services/graphite/graphiteDatasource.js b/src/app/services/graphite/graphiteDatasource.js index 0a8734ea412..423930d04ed 100644 --- a/src/app/services/graphite/graphiteDatasource.js +++ b/src/app/services/graphite/graphiteDatasource.js @@ -17,6 +17,7 @@ function (angular, _, $, config, kbn, moment) { this.type = 'graphite'; this.basicAuth = datasource.basicAuth; this.url = datasource.url; + this.editorSrc = 'app/partials/graphite/editor.html'; } GraphiteDatasource.prototype.query = function(options) { diff --git a/src/app/services/influxdb/influxdbDatasource.js b/src/app/services/influxdb/influxdbDatasource.js new file mode 100644 index 00000000000..66c81844984 --- /dev/null +++ b/src/app/services/influxdb/influxdbDatasource.js @@ -0,0 +1,77 @@ +define([ + 'angular', + 'underscore', +], +function (angular, _) { + 'use strict'; + + var module = angular.module('kibana.services'); + + module.factory('InfluxDatasource', function($q, $http) { + + function InfluxDatasource(datasource) { + this.type = 'influxDB'; + this.editorSrc = 'app/partials/influxDB/editor.html'; + this.url = datasource.url; + this.username = datasource.username; + this.password = datasource.password; + } + + InfluxDatasource.prototype.query = function() { + + var q = "select value from request_count where time > now() - 1h group by time(1m)"; + + var output = { data: [] }; + + return this.doInfluxRequest(q).then(function(results) { + + _.each(results.data, function(series) { + var timeCol = series.columns.indexOf('time'); + + _.each(series.columns, function(column, index) { + if (column === "time" || column === "sequence_number") { + return; + } + + console.log("series:"+series.name + ": "+series.points.length + " points"); + + var target = series.name + "." + column; + var datapoints = []; + + for(var i=0; i < series.points.length; i++) { + var t = Math.floor(series.points[i][timeCol] / 1000); + var v = series.points[i][index]; + datapoints[i] = [v,t]; + } + + output.data.push({ target:target, datapoints:datapoints }); + }); + }); + + return output; + }); + + }; + + InfluxDatasource.prototype.doInfluxRequest = function(query) { + var params = { + u: this.username, + p: this.password, + q: query + }; + + var options = { + method: 'GET', + url: this.url + '/series', + params: params, + }; + + return $http(options); + }; + + + return InfluxDatasource; + + }); + +});