* feat: add memory status for snapshot

* feat: add memory status for snapshot
This commit is contained in:
rookisbusy 2023-04-07 22:55:01 +08:00 committed by GitHub
parent eb07aafce8
commit 36b3581389
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,7 @@
package statistic package statistic
import ( import (
"runtime"
"sync" "sync"
"time" "time"
@ -61,10 +62,17 @@ func (m *Manager) Snapshot() *Snapshot {
return true return true
}) })
getMem := func() uint64 {
var memStats runtime.MemStats
runtime.ReadMemStats(&memStats)
return memStats.StackInuse + memStats.HeapInuse + memStats.HeapIdle - memStats.HeapReleased
}
return &Snapshot{ return &Snapshot{
UploadTotal: m.uploadTotal.Load(), UploadTotal: m.uploadTotal.Load(),
DownloadTotal: m.downloadTotal.Load(), DownloadTotal: m.downloadTotal.Load(),
Connections: connections, Connections: connections,
Memory: getMem(),
} }
} }
@ -92,4 +100,5 @@ type Snapshot struct {
DownloadTotal int64 `json:"downloadTotal"` DownloadTotal int64 `json:"downloadTotal"`
UploadTotal int64 `json:"uploadTotal"` UploadTotal int64 `json:"uploadTotal"`
Connections []tracker `json:"connections"` Connections []tracker `json:"connections"`
Memory uint64 `json:"memory"`
} }