events.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package eventbus
  2. import "time"
  3. // EventType identifies the kind of event flowing through the bus.
  4. type EventType string
  5. const (
  6. // Outbound health (observatory-driven)
  7. EventOutboundDown EventType = "outbound.down"
  8. EventOutboundUp EventType = "outbound.up"
  9. // Xray core (local)
  10. EventXrayCrash EventType = "xray.crash"
  11. // Node health (heartbeat-driven)
  12. EventNodeDown EventType = "node.down"
  13. EventNodeUp EventType = "node.up"
  14. // System health
  15. EventCPUHigh EventType = "cpu.high"
  16. EventMemoryHigh EventType = "memory.high"
  17. // Security
  18. EventLoginAttempt EventType = "login.attempt"
  19. )
  20. // Event is the unit of information flowing through the bus.
  21. type Event struct {
  22. Type EventType
  23. Source string // outbound tag, node name, client email, IP, etc.
  24. Data any // event-specific payload, may be nil
  25. Timestamp time.Time // when the event was detected
  26. }
  27. // OutboundHealthData carries observatory details for outbound events.
  28. type OutboundHealthData struct {
  29. Delay int64 // last measured delay in ms, 0 if unknown
  30. Error string // last error if probe failed, empty if up
  31. }
  32. // NodeHealthData carries heartbeat details for node events.
  33. type NodeHealthData struct {
  34. NodeId int
  35. LatencyMs int
  36. CpuPct float64
  37. MemPct float64
  38. XrayState string // "running", "stopped", etc.
  39. XrayError string
  40. }
  41. // LoginEventData carries login attempt details.
  42. type LoginEventData struct {
  43. Username string
  44. IP string
  45. Time string
  46. Status string // "success" or "fail"
  47. Reason string
  48. }
  49. // SystemMetricData carries raw system metric values for threshold-based events.
  50. type SystemMetricData struct {
  51. Percent float64 // current usage percentage
  52. Threshold int // configured threshold
  53. }