events.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. // Security
  17. EventLoginAttempt EventType = "login.attempt"
  18. )
  19. // Event is the unit of information flowing through the bus.
  20. type Event struct {
  21. Type EventType
  22. Source string // outbound tag, node name, client email, IP, etc.
  23. Data any // event-specific payload, may be nil
  24. Timestamp time.Time // when the event was detected
  25. }
  26. // OutboundHealthData carries observatory details for outbound events.
  27. type OutboundHealthData struct {
  28. Delay int64 // last measured delay in ms, 0 if unknown
  29. Error string // last error if probe failed, empty if up
  30. }
  31. // NodeHealthData carries heartbeat details for node events.
  32. type NodeHealthData struct {
  33. NodeId int
  34. LatencyMs int
  35. CpuPct float64
  36. MemPct float64
  37. XrayState string // "running", "stopped", etc.
  38. XrayError string
  39. }
  40. // LoginEventData carries login attempt details.
  41. type LoginEventData struct {
  42. Username string
  43. IP string
  44. Time string
  45. Status string // "success" or "fail"
  46. Reason string
  47. }
  48. // SystemMetricData carries raw system metric values for threshold-based events.
  49. type SystemMetricData struct {
  50. Percent float64 // current usage percentage
  51. Threshold int // configured threshold
  52. }