datasource.ts 1.1 KB

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