[Groonga-commit] groonga/grafana-datasource-plugin-groonga at bbb1719 [master] Add query() to show data in dashboards

Back to archive index

Masafumi Yokoyama null+****@clear*****
Sun Feb 7 01:37:19 JST 2016


Masafumi Yokoyama	2016-02-07 01:37:19 +0900 (Sun, 07 Feb 2016)

  New Revision: bbb1719c3382816fa81f08f4eef0dd2df6519d9d
  https://github.com/groonga/grafana-datasource-plugin-groonga/commit/bbb1719c3382816fa81f08f4eef0dd2df6519d9d

  Message:
    Add query() to show data in dashboards

  Modified files:
    datasource.js

  Modified: datasource.js (+49 -4)
===================================================================
--- datasource.js    2016-02-07 01:10:35 +0900 (f0ec574)
+++ datasource.js    2016-02-07 01:37:19 +0900 (4615a10)
@@ -6,7 +6,13 @@ function (angular) {
 
   var module = angular.module('grafana.services');
 
-  module.factory('GroongaDatasource', function(backendSrv) {
+  module.factory('GroongaDatasource', function($q,
+                                               $httpParamSerializerJQLike,
+                                               backendSrv) {
+    function params(data) {
+      return $httpParamSerializerJQLike(data);
+    }
+
     function GroongaDatasource(datasource) {
       this.datasource = datasource;
     }
@@ -15,7 +21,7 @@ function (angular) {
       var options = {
         url: this.datasource.url + '/d/status'
       };
-      return backendSrv.datasourceRequest(options).then(function(result) {
+      return backendSrv.datasourceRequest(options).then(function() {
         return {
           status: 'success',
           title: 'Success',
@@ -24,7 +30,46 @@ function (angular) {
       });
     };
 
-    return GroongaDatasource;
-  });
+    GroongaDatasource.prototype.query = function(options) {
+      var selectOptions = {
+        table: 'Logs',
+        filter: 'between(timestamp, ' +
+                         options.range.from.unix() + ', "include", ' +
+                         options.range.to.unix() + ', "include")',
+        'drilldown[code].keys': 'timestamp, code',
+        'drilldown[code].output_columns': '_value.timestamp, _value.code, _nsubrecs',
+        'drilldown[code].sortby': '_value.timestamp',
+        'drilldown[code].limit': -1
+      };
+      var requestOptions = {
+        url: this.datasource.url + '/d/select?' + params(selectOptions)
+      };
+      return backendSrv.datasourceRequest(requestOptions).then(function(result) {
+        var data = []
+        var seriesSet = {};
+        var drilldown = result.data[1][1].code;
+        var i;
+        for (i = 2; i < drilldown.length; i++) {
+          var record = drilldown[i];
+          var timestamp = record[0];
+          var code = record[1];
+          var nCodes = record[2];
+          var series = seriesSet[code];
+          var datapoints;
+          if (!series) {
+            series = seriesSet[code] = {
+              target: code,
+              datapoints: []
+            };
+            data.push(series);
+          }
+          datapoints = series.datapoints;
+          datapoints.push([nCodes, timestamp * 1000]);
+        };
+        return {data: data};
+      });
+    };
 
+     return GroongaDatasource;
+  });
 });
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index