From fcae16bb55c91899e78fe666c6a845dee40ec8bb Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Thu, 8 Jul 2021 19:43:30 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8A=82=E7=82=B9=E7=9C=8B=E6=9D=BF=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=BC=93=E5=AD=98=E7=9B=AE=E5=BD=95=E7=94=A8=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/caches/manager.go | 23 +++++++++++++++++++++++ internal/nodes/node_status_executor.go | 24 ++++++++++++++++++++++++ 2 files changed, 47 insertions(+) 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, + }) +}