maxovertime.go 889 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package aggregator
  2. import (
  3. "sync"
  4. "time"
  5. )
  6. // maxOverTimeAggregator is a MetricAggregator which returns the max value passed to it through the Update function
  7. type maxOverTimeAggregator struct {
  8. lock sync.Mutex
  9. labelValues []string
  10. max float64
  11. }
  12. func MaxOverTime(labelValues []string) MetricAggregator {
  13. return &maxOverTimeAggregator{
  14. labelValues: labelValues,
  15. }
  16. }
  17. func (a *maxOverTimeAggregator) AdditionInfo() map[string]string {
  18. return nil
  19. }
  20. func (a *maxOverTimeAggregator) LabelValues() []string {
  21. return a.labelValues
  22. }
  23. func (a *maxOverTimeAggregator) Update(value float64, timestamp time.Time, additionalInfo map[string]string) {
  24. a.lock.Lock()
  25. defer a.lock.Unlock()
  26. if value > a.max {
  27. a.max = value
  28. }
  29. }
  30. func (a *maxOverTimeAggregator) Value() []MetricValue {
  31. a.lock.Lock()
  32. defer a.lock.Unlock()
  33. return []MetricValue{
  34. {Value: a.max},
  35. }
  36. }