diff --git a/server/listeners.go b/server/listeners.go index 6cac576..6f0494a 100644 --- a/server/listeners.go +++ b/server/listeners.go @@ -122,13 +122,10 @@ func (s *Server) StartEventListeners() { }() case e := <-stats: go func() { - // Update the server resource tracking object with the resources we got here. - s.resources.mu.Lock() - s.resources.Stats = e.Data.(environment.Stats) - s.resources.mu.Unlock() + s.resources.UpdateStats(e.Data.(environment.Stats)) - // If there is no disk space available at this point, trigger the server disk limiter logic - // which will start to stop the running instance. + // If there is no disk space available at this point, trigger the server + // disk limiter logic which will start to stop the running instance. if !s.Filesystem().HasSpaceAvailable(true) { l.Trigger() } diff --git a/server/resources.go b/server/resources.go index 03f2ae5..e11adf5 100644 --- a/server/resources.go +++ b/server/resources.go @@ -38,6 +38,13 @@ func (s *Server) Proc() ResourceUsage { return s.resources } +// UpdateStats updates the current stats for the server's resource usage. +func (ru *ResourceUsage) UpdateStats(stats environment.Stats) { + ru.mu.Lock() + ru.Stats = stats + ru.mu.Unlock() +} + // Reset resets the usages values to zero, used when a server is stopped to ensure we don't hold // onto any values incorrectly. func (ru *ResourceUsage) Reset() {