swap Graphite在Grafana中返回时间戳和值

时间:2016-10-18 12:56:08

标签: javascript graphite grafana

我正在测试Grafana从Graphite系统读取和绘制数据。

这就是Grafana对Graphite的json数据的预期:

plugin.json

我想从中读取数据的系统,交换时间戳和度量值,例如

datasource.js

screenshot 是否可以创建一个新的数据源(来自默认石墨数据源的副本),在处理之前将值交换回来或按原样使用值?

我查看了.js文件,但我发现很难确定需要进行哪些更改,所以任何指针都会受到赞赏!

编辑: 我试过这个:我已经制作了默认Graphite插件的副本,并将其重命名为graphite-copy并调整了datasource.ts中的id。

然后我按照以下方式编辑了 var e = { method: "POST", url: "/render", data: d.join("&"), headers: { "Content-Type": "application/x-www-form-urlencoded" } }; return a.panelId && (e.requestId = this.name + ".panelId." + a.panelId), this.doGraphiteRequest(e).then(this.convertDataPointsToMs) }, this.convertDataPointsToMs = function(a) { if (!a || !a.data) return []; for (var b = 0; b < a.data.length; b++) for (var c = a.data[b], d = 0; d < c.datapoints.length; d++) { var t = c.datapoints[d][0]; c.datapoints[d][0] = c.datapoints[d][1]; c.datapoints[d][0] = t; c.datapoints[d][1] *= 1e3; } var t = c.datapoints[d][0]; c.datapoints[d][0] = c.datapoints[d][1]; c.datapoints[d][0] = t;

datasource.js/ts

改变如下:

{{1}}

我已经为{{1}}中的GET和POST方法做了这个,但它给了我相同的结果(时间戳和度量标准切换)。

1 个答案:

答案 0 :(得分:0)

您可以使用angular

angular.factory中执行相应操作
var module = angular.module(grafana.services);

module.factory('Datasrc',function($q, backendsrv, templatesrv){

//$q,backendsrv templatesrv supported by grafana

 function Datasrc(datasource){
     this.type =// the datasource type;

     this.url = datasource.url;

     this.auth = datasource.basicAuth;

     this.timestamp = true;

     this.supportMetrics = true;
 }

 AtsdDatasource.prototype.query = function (options) {


 var queries = _.compact(qs);

 if (_.isEmpty(queries)) {
          var d = $q.defer();
          d.resolve({ data: [] });
          return d.promise;
}

Datasrc.prototype._performQuery = function (queries) {
    var query = [];
    query.push( 
     { 
        data :[
               objecttype = query.type,
               datapoints = query.//swap the values here
               //enter the other necessary fields or declare more in the factory

               ]
           });

if (query.length === 0) {
          var d = $q.defer();
          d.resolve({ data: undefined });
          return d.promise;          //promise called here
}



var options = {
          method: 'POST',
          url: this.url + '/api/v1/series',
          data: {
            queries: tsQueries
          },
          headers: {
            Authorization: this.basicAuth
          }
        };

        return backendSrv.datasourceRequest(options).then(function (result) {
          return result;
        });
};

     }
});

完全归因于author和GitHub link