I am testing with Grafana to read and graph data from a Graphite system.
This is how Grafana expects json data from Graphite:
{
"data": [
{
"target": "test-series-0",
"datapoints": [
[
22.504392773143504,
1.476693264195e+12
],
[
22.719552781746028,
1.476693301825e+12
]
]
}
]
}
The system that I want to read data from, swaps timestamp and metric value, e.g.
{
"data": [
{
"target": "test-series-0",
"datapoints": [
[
1.476693264195e+12
22.504392773143504,
],
[
1.476693301825e+12
22.719552781746028,
]
]
}
]
}
Is it possible to create a new datasource (a copy from the default graphite datasource) that either swaps the values back before processing or work with the values as is?
I have looked at the .js files but I find it hard to determine where I need to make changes so any pointers are appreciated!
EDIT:
I have tried this: I have made a copy of the default Graphite plugin and have renamed it to graphite-copy and adjusted the id in plugin.json
.
Then I edited datasource.js
and datasource.ts
like this:
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;
}
With the change being this:
var t = c.datapoints[d][0];
c.datapoints[d][0] = c.datapoints[d][1];
c.datapoints[d][0] = t;
I have done this for both GET and POST methods in datasource.js/ts
but it gives me same result (timestamp and metric switched).