reducer.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package monitor
  15. import "yunion.io/x/pkg/util/sets"
  16. type ReducerType string
  17. const (
  18. REDUCER_AVG ReducerType = "avg"
  19. REDUCER_SUM ReducerType = "sum"
  20. REDUCER_MIN ReducerType = "min"
  21. REDUCER_MAX ReducerType = "max"
  22. REDUCER_COUNT ReducerType = "count"
  23. REDUCER_LAST ReducerType = "last"
  24. REDUCER_MEDIAN ReducerType = "median"
  25. REDUCER_DIFF ReducerType = "diff"
  26. REDUCER_DELTA ReducerType = "delta"
  27. REDUCER_PERCENT_DIFF ReducerType = "percent_diff"
  28. REDUCER_COUNT_NON_NULL ReducerType = "count_non_null"
  29. REDUCER_PERCENTILE ReducerType = "percentile"
  30. )
  31. var ValidateReducerTypes = sets.NewString()
  32. func init() {
  33. for _, rt := range []ReducerType{REDUCER_AVG, REDUCER_SUM, REDUCER_MIN,
  34. REDUCER_MAX, REDUCER_COUNT, REDUCER_LAST, REDUCER_MEDIAN, REDUCER_DIFF,
  35. REDUCER_DELTA, REDUCER_PERCENT_DIFF, REDUCER_COUNT_NON_NULL, REDUCER_PERCENTILE} {
  36. ValidateReducerTypes.Insert(string(rt))
  37. }
  38. }
  39. type ReducedResult struct {
  40. Reducer Condition `json:"reducer"`
  41. Result []float64 `json:"result"`
  42. }