Last active
August 20, 2020 00:01
-
-
Save athulmurali/bb92142961813da525d084badbd9203c to your computer and use it in GitHub Desktop.
grafana-datasource.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// original code | |
async query(options) { | |
var query = await this.buildQueryParameters(options); | |
if (query.targets.length <= 0) { | |
return this.q.when({ data: [] }); | |
} | |
return this.doRequest(query).then(result => { | |
var res = [] | |
_.forEach(result.data.results, r => { | |
_.forEach(r.series, s => { | |
res.push({ target: s.name, datapoints: s.points }) | |
}) | |
_.forEach(r.tables, t => { | |
t.type = 'table' | |
t.refId = r.refId | |
res.push(t) | |
}) | |
}) | |
// test code with hardcoded data for log panel | |
import * as graf from '@grafana/data' | |
async query(options) { | |
const MutableDataFrame = graf.MutableDataFrame; | |
const FieldType = graf.FieldType; | |
const frame = new MutableDataFrame({ | |
refId: query.refId, | |
fields: [ | |
{ name: 'time', type: FieldType.time }, | |
{ name: 'content', type: FieldType.string, labels: { filename: 'file.txt' } } | |
], | |
}); | |
frame.add({ time: 1589189388597, content: 'user registered' }) | |
frame.add({ time: 1589189406480, content: 'user logged in' }) | |
console.log('frame to JSON' , frame.toJSON()) | |
result.data = frame.toJSON() | |
return result | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment