From 36b35813894641ff102449d0324ce63d7ce15271 Mon Sep 17 00:00:00 2001 From: rookisbusy <129355218+rookisbusy@users.noreply.github.com> Date: Fri, 7 Apr 2023 22:55:01 +0800 Subject: [PATCH] Alpha (#490) * feat: add memory status for snapshot * feat: add memory status for snapshot --- tunnel/statistic/manager.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tunnel/statistic/manager.go b/tunnel/statistic/manager.go index e67d3871..251450fb 100644 --- a/tunnel/statistic/manager.go +++ b/tunnel/statistic/manager.go @@ -1,6 +1,7 @@ package statistic import ( + "runtime" "sync" "time" @@ -61,10 +62,17 @@ func (m *Manager) Snapshot() *Snapshot { return true }) + getMem := func() uint64 { + var memStats runtime.MemStats + runtime.ReadMemStats(&memStats) + return memStats.StackInuse + memStats.HeapInuse + memStats.HeapIdle - memStats.HeapReleased + } + return &Snapshot{ UploadTotal: m.uploadTotal.Load(), DownloadTotal: m.downloadTotal.Load(), Connections: connections, + Memory: getMem(), } } @@ -92,4 +100,5 @@ type Snapshot struct { DownloadTotal int64 `json:"downloadTotal"` UploadTotal int64 `json:"uploadTotal"` Connections []tracker `json:"connections"` + Memory uint64 `json:"memory"` }