diff --git a/internal/caches/manager.go b/internal/caches/manager.go index fc424fa..28133d6 100644 --- a/internal/caches/manager.go +++ b/internal/caches/manager.go @@ -5,6 +5,7 @@ import ( "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared" "github.com/TeaOSLab/EdgeNode/internal/remotelogs" "github.com/iwind/TeaGo/lists" + "github.com/iwind/TeaGo/types" "strconv" "sync" ) @@ -162,3 +163,25 @@ func (this *Manager) TotalMemorySize() int64 { } return total } + +// FindAllCachePaths 所有缓存路径 +func (this *Manager) FindAllCachePaths() []string { + this.locker.Lock() + defer this.locker.Unlock() + + var result = []string{} + for _, policy := range this.policyMap { + if policy.Type == serverconfigs.CachePolicyStorageFile { + if policy.Options != nil { + dir, ok := policy.Options["dir"] + if ok { + var dirString = types.String(dir) + if len(dirString) > 0 { + result = append(result, dirString) + } + } + } + } + } + return result +} diff --git a/internal/nodes/node_status_executor.go b/internal/nodes/node_status_executor.go index 9d3dde8..731a8c4 100644 --- a/internal/nodes/node_status_executor.go +++ b/internal/nodes/node_status_executor.go @@ -15,6 +15,7 @@ import ( "github.com/iwind/TeaGo/maps" "github.com/shirou/gopsutil/cpu" "github.com/shirou/gopsutil/disk" + "golang.org/x/sys/unix" "os" "runtime" "strings" @@ -82,6 +83,7 @@ func (this *NodeStatusExecutor) update() { this.updateMem(status) this.updateLoad(status) this.updateDisk(status) + this.updateCacheSpace(status) status.UpdatedAt = time.Now().Unix() // 发送数据 @@ -213,3 +215,25 @@ func (this *NodeStatusExecutor) updateDisk(status *nodeconfigs.NodeStatus) { "maxUsage": status.DiskMaxUsage, }) } + +// 缓存空间 +func (this *NodeStatusExecutor) updateCacheSpace(status *nodeconfigs.NodeStatus) { + var result = []maps.Map{} + cachePaths := caches.SharedManager.FindAllCachePaths() + for _, path := range cachePaths { + var stat unix.Statfs_t + err := unix.Statfs(path, &stat) + if err != nil { + return + } + result = append(result, maps.Map{ + "path": path, + "total": stat.Blocks * uint64(stat.Bsize), + "avail": stat.Bavail * uint64(stat.Bsize), + "used": (stat.Blocks - stat.Bavail) * uint64(stat.Bsize), + }) + } + monitor.SharedValueQueue.Add(nodeconfigs.NodeValueItemCacheDir, maps.Map{ + "dirs": result, + }) +}