diff --git a/server/environment_docker.go b/server/environment_docker.go index 17445c4..a558c40 100644 --- a/server/environment_docker.go +++ b/server/environment_docker.go @@ -289,7 +289,7 @@ func (d *DockerEnvironment) EnableResourcePolling() error { pCpu := 0.0 pSystem := 0.0 - for { + for { var v *types.StatsJSON if err := dec.Decode(&v); err != nil { @@ -308,7 +308,10 @@ func (d *DockerEnvironment) EnableResourcePolling() error { s.Resources.CpuAbsolute = s.Resources.CalculateAbsoluteCpu(pCpu, pSystem, &v.CPUStats) s.Resources.Memory = v.MemoryStats.Usage s.Resources.MemoryLimit = v.MemoryStats.Limit - s.Resources.Disk = 0 + + // Why you ask? This already has the logic for caching disk space in use and then + // also handles pushing that value to the resources object automatically. + s.Filesystem.HasSpaceAvailable() for _, nw := range v.Networks { s.Resources.Network.RxBytes += nw.RxBytes @@ -326,7 +329,14 @@ func (d *DockerEnvironment) DisableResourcePolling() error { return nil } - return d.stats.Close() + err := d.stats.Close() + + d.Server.Resources.CpuAbsolute = 0 + d.Server.Resources.Memory = 0 + d.Server.Resources.Network.TxBytes = 0 + d.Server.Resources.Network.RxBytes = 0 + + return err } // Creates a new container for the server using all of the data that is currently @@ -597,4 +607,4 @@ func (d *DockerEnvironment) exposedPorts() nat.PortSet { } return out -} \ No newline at end of file +} diff --git a/server/filesystem.go b/server/filesystem.go index 30d91b0..de51d50 100644 --- a/server/filesystem.go +++ b/server/filesystem.go @@ -130,13 +130,15 @@ func (fs *Filesystem) HasSpaceAvailable() bool { if size, err := fs.DirectorySize("/"); err != nil { zap.S().Warnw("failed to determine directory size", zap.String("server", fs.Server.Uuid), zap.Error(err)) } else { - fs.Server.Cache.Set("disk_used", size, time.Minute*5) + fs.Server.Cache.Set("disk_used", size, time.Second * 60) } } // Determine if their folder size, in bytes, is smaller than the amount of space they've // been allocated. - return (size / 1024.0 / 1024.0) <= space + fs.Server.Resources.Disk = size + + return (size / 1000.0 / 1000.0) <= space } // Determines the directory size of a given location by running parallel tasks to iterate diff --git a/server/resources.go b/server/resources.go index 83e8ba9..44425dc 100644 --- a/server/resources.go +++ b/server/resources.go @@ -20,7 +20,7 @@ type ResourceUsage struct { CpuAbsolute float64 `json:"cpu_absolute"` // The current disk space being used by the server. This is cached to prevent slow lookup // issues on frequent refreshes. - Disk uint64 `json:"disk_bytes"` + Disk int64 `json:"disk_bytes"` // Current network transmit in & out for a container. Network struct { RxBytes uint64 `json:"rx_bytes"` @@ -47,5 +47,5 @@ func (ru *ResourceUsage) CalculateAbsoluteCpu(previousCpu, previousSystem float6 percent = (cpuDelta / systemDelta) * cpus * 100.0 } - return math.Round(percent * 1000) / 1000 -} \ No newline at end of file + return math.Round(percent*1000) / 1000 +}