Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

69 linhas
1.8 KiB

  1. package appcontext
  2. import (
  3. "encoding/json"
  4. "time"
  5. "github.com/AFASystems/presence/internal/pkg/kafkaclient"
  6. )
  7. // ServiceStatus represents the health of an external service (e.g. Kafka, database).
  8. type ServiceStatus struct {
  9. Status string `json:"status"` // "up", "down", "unknown"
  10. Message string `json:"message,omitempty"`
  11. }
  12. type BaseHealth struct {
  13. Uptime time.Duration `json:"uptime"`
  14. ActiveReaders []string `json:"activeReaders" gorm:"type:jsonb"`
  15. ActiveWriters []string `json:"activeWriters" gorm:"type:jsonb"`
  16. }
  17. type DecoderHealth struct {
  18. BaseHealth
  19. // current active configs ? dont know yet how
  20. }
  21. type LocationHealth struct {
  22. BaseHealth
  23. ActiveBeacons []string `json:"activeBeacons" gorm:"type:jsonb"`
  24. ActiveSettings []Settings `json:"activeSettings" gorm:"type:jsonb"`
  25. }
  26. type BridgeHealth struct {
  27. BaseHealth
  28. ActiveBeacons []string `json:"activeBeacons" gorm:"type:jsonb"`
  29. }
  30. type Health struct {
  31. Location LocationHealth `json:"location" gorm:"embedded;embeddedPrefix:loc_"`
  32. Decoder DecoderHealth `json:"decoder" gorm:"embedded;embeddedPrefix:dec_"`
  33. Bridge BridgeHealth `json:"bridge" gorm:"embedded;embeddedPrefix:brg_"`
  34. Kafka ServiceStatus `json:"kafka"`
  35. Database ServiceStatus `json:"database"`
  36. }
  37. func (b *BaseHealth) GetUptime(startTime time.Time) {
  38. b.Uptime = time.Since(startTime)
  39. }
  40. func (b *BaseHealth) GetActiveReaders(m *kafkaclient.KafkaManager) {
  41. b.ActiveReaders = m.GetReaders()
  42. }
  43. func (b *BaseHealth) GetActiveWriters(m *kafkaclient.KafkaManager) {
  44. b.ActiveWriters = m.GetWriters()
  45. }
  46. func (d *DecoderHealth) Marshal() ([]byte, error) {
  47. return json.Marshal(d)
  48. }
  49. func (l *LocationHealth) Marshal() ([]byte, error) {
  50. return json.Marshal(l)
  51. }
  52. func (b *BridgeHealth) Marshal() ([]byte, error) {
  53. return json.Marshal(b)
  54. }