models.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package elasticsearch
  2. import (
  3. "github.com/grafana/grafana/pkg/components/simplejson"
  4. )
  5. // Query represents the time series query model of the datasource
  6. type Query struct {
  7. TimeField string `json:"timeField"`
  8. RawQuery string `json:"query"`
  9. BucketAggs []*BucketAgg `json:"bucketAggs"`
  10. Metrics []*MetricAgg `json:"metrics"`
  11. Alias string `json:"alias"`
  12. Interval string
  13. RefID string
  14. }
  15. // BucketAgg represents a bucket aggregation of the time series query model of the datasource
  16. type BucketAgg struct {
  17. Field string `json:"field"`
  18. ID string `json:"id"`
  19. Settings *simplejson.Json `json:"settings"`
  20. Type string `jsons:"type"`
  21. }
  22. // MetricAgg represents a metric aggregation of the time series query model of the datasource
  23. type MetricAgg struct {
  24. Field string `json:"field"`
  25. Hide bool `json:"hide"`
  26. ID string `json:"id"`
  27. PipelineAggregate string `json:"pipelineAgg"`
  28. Settings *simplejson.Json `json:"settings"`
  29. Meta *simplejson.Json `json:"meta"`
  30. Type string `json:"type"`
  31. }
  32. var metricAggType = map[string]string{
  33. "count": "Count",
  34. "avg": "Average",
  35. "sum": "Sum",
  36. "max": "Max",
  37. "min": "Min",
  38. "extended_stats": "Extended Stats",
  39. "percentiles": "Percentiles",
  40. "cardinality": "Unique Count",
  41. "moving_avg": "Moving Average",
  42. "derivative": "Derivative",
  43. "raw_document": "Raw Document",
  44. }
  45. var extendedStats = map[string]string{
  46. "avg": "Avg",
  47. "min": "Min",
  48. "max": "Max",
  49. "sum": "Sum",
  50. "count": "Count",
  51. "std_deviation": "Std Dev",
  52. "std_deviation_bounds_upper": "Std Dev Upper",
  53. "std_deviation_bounds_lower": "Std Dev Lower",
  54. }
  55. var pipelineAggType = map[string]string{
  56. "moving_avg": "moving_avg",
  57. "derivative": "derivative",
  58. }
  59. func isPipelineAgg(metricType string) bool {
  60. if _, ok := pipelineAggType[metricType]; ok {
  61. return true
  62. }
  63. return false
  64. }
  65. func describeMetric(metricType, field string) string {
  66. text := metricAggType[metricType]
  67. if metricType == countType {
  68. return text
  69. }
  70. return text + " " + field
  71. }