Rem*_*mko 6 javascript graphite grafana
我正在测试Grafana从Graphite系统读取和绘制数据.
这就是Grafana对Graphite的json数据的预期:
{
"data": [
{
"target": "test-series-0",
"datapoints": [
[
22.504392773143504,
1.476693264195e+12
],
[
22.719552781746028,
1.476693301825e+12
]
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
我想从中读取数据的系统,交换时间戳和度量值,例如
{
"data": [
{
"target": "test-series-0",
"datapoints": [
[
1.476693264195e+12
22.504392773143504,
],
[
1.476693301825e+12
22.719552781746028,
]
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
是否可以创建一个新的数据源(来自默认石墨数据源的副本),在处理之前将值交换回来或按原样使用值?
我查看了.js文件,但我发现很难确定我需要进行哪些更改,所以任何指针都很受欢迎!
编辑:我试过这个:我已经制作了默认的Graphite插件的副本,并将其重命名为graphite-copy并调整了id plugin.json.
然后我编辑datasource.js并datasource.ts喜欢这样:
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;
}
Run Code Online (Sandbox Code Playgroud)
随着变化是这样的:
var t = c.datapoints[d][0];
c.datapoints[d][0] = c.datapoints[d][1];
c.datapoints[d][0] = t;
Run Code Online (Sandbox Code Playgroud)
我已经为GET和POST方法做了这个,datasource.js/ts但它给了我相同的结果(时间戳和度量切换).
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;
});
};
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
294 次 |
| 最近记录: |