From 6cd1bc32fede21ef2f835365a4df2c8c53f956ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 15 Oct 2014 17:29:47 -0400 Subject: [PATCH] StatsPanel: more work on stats panel --- src/app/panels/stats/module.html | 53 +++++++-------- src/app/panels/stats/module.js | 96 +++++++++++++++++++++++---- src/app/panels/stats/statsEditor.html | 27 ++++++++ src/css/less/panel.less | 1 - 4 files changed, 137 insertions(+), 40 deletions(-) create mode 100644 src/app/panels/stats/statsEditor.html diff --git a/src/app/panels/stats/module.html b/src/app/panels/stats/module.html index 8f57380c7c0..64e61cacc69 100644 --- a/src/app/panels/stats/module.html +++ b/src/app/panels/stats/module.html @@ -1,31 +1,32 @@
+
-
- {{mainstat.value}} - ({{mainstat.func}}) -
- - - - - - - - - - - - - - - - - - -
avgminmaxcurrenttotal
- - {{series.info.alias}} - {{series.info.avg}}{{series.info.min}}{{series.info.max}}{{series.info.current}}{{series.info.total}}
+ + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/app/panels/stats/module.js b/src/app/panels/stats/module.js index 08a078f27b5..471d6db4f41 100644 --- a/src/app/panels/stats/module.js +++ b/src/app/panels/stats/module.js @@ -25,6 +25,10 @@ function (angular, app, _, TimeSeries, kbn) { { title: 'Metrics', src:'app/partials/metrics.html' + }, + { + title: 'Display Styles', + src:'app/panels/stats/statsEditor.html' } ], fullscreenEdit: true, @@ -32,28 +36,35 @@ function (angular, app, _, TimeSeries, kbn) { // Set and populate defaults var _d = { - targets: [{}] + targets: [{}], + cacheTimeout: null, }; _.defaults($scope.panel, _d); $scope.init = function() { panelSrv.init($scope); + $scope.$on('refresh', $scope.get_data); }; $scope.formatValue = function(value) { return kbn.valueFormats.bytes(value, 0, -7); }; - $scope.get_data = function() { - console.log("stats get data"); + $scope.updateTimeRange = function () { + $scope.range = timeSrv.timeRange(); $scope.rangeUnparsed = timeSrv.timeRange(false); + }; + + $scope.get_data = function() { + $scope.updateTimeRange(); var metricsQuery = { range: $scope.rangeUnparsed, interval: '1min', targets: $scope.panel.targets, maxDataPoints: 100, + cacheTimeout: $scope.panel.cacheTimeout }; return $scope.datasource.query(metricsQuery) @@ -63,20 +74,26 @@ function (angular, app, _, TimeSeries, kbn) { $scope.panelMeta.loading = false; $scope.panelMeta.error = err.message || "Timeseries data request error"; $scope.inspector.error = err; - $scope.render([]); + $scope.render(); }); }; $scope.dataHandler = function(results) { $scope.panelMeta.loading = false; - $scope.series = _.map(results.data, $scope.seriesHandler); + var data= {}; + data.series = _.map(results.data, $scope.seriesHandler); + data.stats = []; - if ($scope.series.length > 0) { - var mainstat = $scope.series[0]; - $scope.mainstat = {}; - $scope.mainstat.value = $scope.formatValue(mainstat.stats.avg); - $scope.mainstat.func = 'avg'; + if (data.series.length > 0) { + var stat = {}; + var firstSeries = data.series[0]; + stat.value = $scope.formatValue(firstSeries.stats.avg); + stat.func = 'avg'; + data.stats.push(stat); } + + $scope.data = data; + $scope.render(); }; $scope.seriesHandler = function(seriesData, index) { @@ -102,11 +119,64 @@ function (angular, app, _, TimeSeries, kbn) { }; $scope.render = function() { - }; - - $scope.openEditor = function() { + $scope.$emit('render'); }; $scope.init(); }); + + module.directive('statsPanel', function() { + + return { + link: function(scope, elem) { + var data; + + console.log('asd'); + scope.$on('render', function() { + data = scope.data; + + if (!data || data.series.length === 0) { + elem.html('no data'); + return; + } + + render(); + }); + + function render() { + var body = ''; + var i, series; + + if (scope.panel.stats) { + body += '
'; + body += '' + data.stats[0].value + ''; + body += ' (' + data.stats[0].func + ')'; + body += '
'; + } + + if (scope.panel.table) { + body += ''; + body += ''; + body += ''; + body += ''; + for (i = 0; i < data.series.length; i++) { + series = data.series[i]; + body += ''; + body += ''; + body += ''; + body += ''; + body += ''; + body += ''; + body += ''; + } + body += '
avgminmaxcurrenttotal
'; + body += series.info.alias + ' ' + series.info.avg + '' + series.info.min + '' + series.info.max + '' + series.info.total + '' + series.info.current + '
'; + } + + elem.html(body); + } + } + }; + }); + }); diff --git a/src/app/panels/stats/statsEditor.html b/src/app/panels/stats/statsEditor.html new file mode 100644 index 00000000000..cb473e03122 --- /dev/null +++ b/src/app/panels/stats/statsEditor.html @@ -0,0 +1,27 @@ +
+
+
Main options
+ + +
+
+ +
+
+
Series options
+
+
+
    +
  • + {{series.info.alias}} +
  • + +
  • +
  • +
+
+
+
+
+
+ diff --git a/src/css/less/panel.less b/src/css/less/panel.less index 00b7744ece6..a2891fb6291 100644 --- a/src/css/less/panel.less +++ b/src/css/less/panel.less @@ -40,7 +40,6 @@ text-align: center; } - .panel-error { color: @white; position: absolute;