system.go 848 B

123456789101112131415161718192021222324252627282930313233343536
  1. package system
  2. import (
  3. "go.uber.org/zap"
  4. "godash/hub"
  5. "time"
  6. )
  7. func NewSystemService(enabled bool, logging *zap.SugaredLogger, hub *hub.Hub) *System {
  8. var s System
  9. if enabled {
  10. s = System{log: logging, hub: hub}
  11. s.Initialize()
  12. }
  13. return &s
  14. }
  15. func (s *System) UpdateLiveInformation() {
  16. for {
  17. s.liveCpu()
  18. s.liveRam()
  19. s.liveDisk()
  20. s.uptime()
  21. s.hub.LiveInformationCh <- hub.Message{WsType: hub.System, Message: s.CurrentSystem.Live}
  22. time.Sleep(1 * time.Second)
  23. }
  24. }
  25. func (s *System) Initialize() {
  26. s.CurrentSystem.Static.Host = staticHost()
  27. s.CurrentSystem.Static.CPU = staticCpu()
  28. s.CurrentSystem.Static.Ram = staticRam()
  29. s.CurrentSystem.Static.Disk = staticDisk()
  30. go s.UpdateLiveInformation()
  31. s.log.Debugw("system updated", "cpu", s.CurrentSystem.Static.CPU.Name, "arch", s.CurrentSystem.Static.Host.Architecture)
  32. }