metrics.go 865 B

123456789101112131415161718192021222324252627282930313233343536
  1. package api
  2. import (
  3. "github.com/grafana/grafana/pkg/api/dtos"
  4. "github.com/grafana/grafana/pkg/middleware"
  5. "math/rand"
  6. "strconv"
  7. )
  8. func GetTestMetrics(c *middleware.Context) {
  9. from := c.QueryInt64("from")
  10. to := c.QueryInt64("to")
  11. maxDataPoints := c.QueryInt64("maxDataPoints")
  12. stepInSeconds := (to - from) / maxDataPoints
  13. result := dtos.MetricQueryResultDto{}
  14. result.Data = make([]dtos.MetricQueryResultDataDto, 1)
  15. for seriesIndex := range result.Data {
  16. points := make([][2]float64, maxDataPoints)
  17. walker := rand.Float64() * 100
  18. time := from
  19. for i := range points {
  20. points[i][0] = walker
  21. points[i][1] = float64(time)
  22. walker += rand.Float64() - 0.5
  23. time += stepInSeconds
  24. }
  25. result.Data[seriesIndex].Target = "test-series-" + strconv.Itoa(seriesIndex)
  26. result.Data[seriesIndex].DataPoints = points
  27. }
  28. c.JSON(200, &result)
  29. }