datasource.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. ///<reference path="../../../headers/common.d.ts" />
  2. import _ from 'lodash';
  3. class GrafanaDatasource {
  4. /** @ngInject */
  5. constructor(private backendSrv) {}
  6. query(options) {
  7. return this.backendSrv.post('/api/tsdb/query', {
  8. from: options.range.from.valueOf().toString(),
  9. to: options.range.to.valueOf().toString(),
  10. queries: [
  11. {
  12. "refId": "A",
  13. "scenarioId": "random_walk",
  14. "intervalMs": options.intervalMs,
  15. "maxDataPoints": options.maxDataPoints,
  16. }
  17. ]
  18. }).then(res => {
  19. var data = [];
  20. if (res.results) {
  21. _.forEach(res.results, queryRes => {
  22. for (let series of queryRes.series) {
  23. data.push({
  24. target: series.name,
  25. datapoints: series.points
  26. });
  27. }
  28. });
  29. }
  30. return {data: data};
  31. });
  32. }
  33. annotationQuery(options) {
  34. return this.backendSrv.get('/api/annotations', {
  35. from: options.range.from.valueOf(),
  36. to: options.range.to.valueOf(),
  37. limit: options.limit,
  38. type: options.type,
  39. });
  40. }
  41. }
  42. export {GrafanaDatasource};