25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 

75 satır
1.9 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. ActiveBeacons []string `json:"activeBeacons" gorm:"type:jsonb"`
  17. }
  18. type DecoderHealth struct {
  19. BaseHealth
  20. // current active configs ? dont know yet how
  21. }
  22. type LocationHealth struct {
  23. BaseHealth
  24. ActiveSettings []Settings `json:"activeSettings" gorm:"type:jsonb"`
  25. }
  26. type BridgeHealth struct {
  27. BaseHealth
  28. }
  29. type Health struct {
  30. Location LocationHealth `json:"location" gorm:"embedded;embeddedPrefix:loc_"`
  31. Decoder DecoderHealth `json:"decoder" gorm:"embedded;embeddedPrefix:dec_"`
  32. Bridge BridgeHealth `json:"bridge" gorm:"embedded;embeddedPrefix:brg_"`
  33. Kafka ServiceStatus `json:"kafka"`
  34. Database ServiceStatus `json:"database"`
  35. }
  36. func (b *BaseHealth) GetUptime(startTime time.Time) {
  37. b.Uptime = time.Since(startTime)
  38. }
  39. func (b *BaseHealth) GetActiveReaders(m *kafkaclient.KafkaManager) {
  40. b.ActiveReaders = m.GetReaders()
  41. }
  42. func (b *BaseHealth) GetActiveWriters(m *kafkaclient.KafkaManager) {
  43. b.ActiveWriters = m.GetWriters()
  44. }
  45. func (b *BaseHealth) GetActiveBeacons(m *AppState) {
  46. beacons := m.GetAllBeacons()
  47. for beacon := range beacons {
  48. b.ActiveBeacons = append(b.ActiveBeacons, beacon)
  49. }
  50. }
  51. func (d *DecoderHealth) Marshal() ([]byte, error) {
  52. return json.Marshal(d)
  53. }
  54. func (l *LocationHealth) Marshal() ([]byte, error) {
  55. return json.Marshal(l)
  56. }
  57. func (b *BridgeHealth) Marshal() ([]byte, error) {
  58. return json.Marshal(b)
  59. }