You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

72 line
1.5 KiB

  1. package model
  2. import (
  3. "encoding/json"
  4. "sync"
  5. "time"
  6. "github.com/AFASystems/presence/internal/pkg/common/appcontext"
  7. "github.com/AFASystems/presence/internal/pkg/kafkaclient"
  8. )
  9. type BaseHealth struct {
  10. Lock sync.RWMutex
  11. Uptime time.Duration `json:"uptime"`
  12. ActiveReaders []string `json:"activeReaders"`
  13. ActiveWriters []string `json:"activeWriters"`
  14. ActiveBeacons []string `json:"activeBeacons"`
  15. }
  16. type DecoderHealth struct {
  17. BaseHealth
  18. // current active configs ? dont know yet how
  19. }
  20. type LocationHealth struct {
  21. BaseHealth
  22. ActiveSettings []appcontext.Settings `json:"activeSettings"`
  23. }
  24. type BridgeHealth struct {
  25. BaseHealth
  26. }
  27. func (b *BaseHealth) GetUptime(startTime time.Time) {
  28. b.Lock.Lock()
  29. b.Uptime = time.Since(startTime)
  30. b.Lock.Unlock()
  31. }
  32. func (b *BaseHealth) GetActiveReaders(m *kafkaclient.KafkaManager) {
  33. b.Lock.Lock()
  34. b.ActiveReaders = m.GetReaders()
  35. b.Lock.Unlock()
  36. }
  37. func (b *BaseHealth) GetActiveWriters(m *kafkaclient.KafkaManager) {
  38. b.Lock.Lock()
  39. b.ActiveWriters = m.GetWriters()
  40. b.Lock.Unlock()
  41. }
  42. func (b *BaseHealth) GetActiveBeacons(m *appcontext.AppState) {
  43. b.Lock.Lock()
  44. beacons := m.GetAllBeacons()
  45. for beacon := range beacons {
  46. b.ActiveBeacons = append(b.ActiveBeacons, beacon)
  47. }
  48. b.Lock.Unlock()
  49. }
  50. func (d *DecoderHealth) Marshal() ([]byte, error) {
  51. return json.Marshal(d)
  52. }
  53. func (l *LocationHealth) Marshal() ([]byte, error) {
  54. return json.Marshal(l)
  55. }
  56. func (b *BridgeHealth) Marshal() ([]byte, error) {
  57. return json.Marshal(b)
  58. }