models.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package tsdb
  2. import (
  3. "github.com/grafana/grafana/pkg/components/null"
  4. "github.com/grafana/grafana/pkg/components/simplejson"
  5. "github.com/grafana/grafana/pkg/models"
  6. )
  7. type TsdbQuery struct {
  8. TimeRange *TimeRange
  9. Queries []*Query
  10. }
  11. type Query struct {
  12. RefId string
  13. Model *simplejson.Json
  14. Depends []string
  15. DataSource *models.DataSource
  16. Results []*TimeSeries
  17. MaxDataPoints int64
  18. IntervalMs int64
  19. }
  20. type Response struct {
  21. Results map[string]*QueryResult `json:"results"`
  22. Message string `json:"message,omitempty"`
  23. }
  24. type QueryResult struct {
  25. Error error `json:"-"`
  26. ErrorString string `json:"error,omitempty"`
  27. RefId string `json:"refId"`
  28. Meta *simplejson.Json `json:"meta,omitempty"`
  29. Series TimeSeriesSlice `json:"series"`
  30. Tables []*Table `json:"tables"`
  31. }
  32. type TimeSeries struct {
  33. Name string `json:"name"`
  34. Points TimeSeriesPoints `json:"points"`
  35. Tags map[string]string `json:"tags,omitempty"`
  36. }
  37. type Table struct {
  38. Columns []TableColumn `json:"columns"`
  39. Rows []RowValues `json:"rows"`
  40. }
  41. type TableColumn struct {
  42. Text string `json:"text"`
  43. }
  44. type RowValues []interface{}
  45. type TimePoint [2]null.Float
  46. type TimeSeriesPoints []TimePoint
  47. type TimeSeriesSlice []*TimeSeries
  48. func NewQueryResult() *QueryResult {
  49. return &QueryResult{
  50. Series: make(TimeSeriesSlice, 0),
  51. }
  52. }
  53. func NewTimePoint(value null.Float, timestamp float64) TimePoint {
  54. return TimePoint{value, null.FloatFrom(timestamp)}
  55. }
  56. func NewTimeSeriesPointsFromArgs(values ...float64) TimeSeriesPoints {
  57. points := make(TimeSeriesPoints, 0)
  58. for i := 0; i < len(values); i += 2 {
  59. points = append(points, NewTimePoint(null.FloatFrom(values[i]), values[i+1]))
  60. }
  61. return points
  62. }
  63. func NewTimeSeries(name string, points TimeSeriesPoints) *TimeSeries {
  64. return &TimeSeries{
  65. Name: name,
  66. Points: points,
  67. }
  68. }