state.go 762 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package shared
  2. import "time"
  3. type Kind int8
  4. const (
  5. KindInput Kind = iota
  6. KindFilter
  7. KindOutput
  8. KindAll // sentinel for filtering
  9. )
  10. func (k Kind) String() string { return [...]string{"input", "filter", "output", "all"}[k] }
  11. type ComponentMetrics struct {
  12. ID string
  13. Kind Kind
  14. Fields map[string]int64
  15. Stamp time.Time
  16. }
  17. func (c ComponentMetrics) Records() int64 {
  18. if c.Kind == KindOutput {
  19. return c.Fields["proc_records"]
  20. }
  21. return c.Fields["records"]
  22. }
  23. func (c ComponentMetrics) Bytes() int64 {
  24. if c.Kind == KindOutput {
  25. return c.Fields["proc_bytes"]
  26. }
  27. return c.Fields["bytes"]
  28. }
  29. type State struct {
  30. Comps []ComponentMetrics
  31. PrevComps []ComponentMetrics // snapshot for rate computation
  32. Connected bool
  33. UpdatedAt time.Time
  34. }