Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

71 righe
1.4 KiB

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