chore: remove depend of gopsutil

This commit is contained in:
wwqgtxx
2025-09-24 02:21:47 +08:00
parent 0c25831726
commit 0992ee8adf
19 changed files with 1424 additions and 33 deletions

View File

@@ -0,0 +1,37 @@
package memory
import (
"os"
"path/filepath"
"strconv"
"strings"
)
var pageSize = uint64(os.Getpagesize())
func GetMemoryInfo(pid int32) (*MemoryInfoStat, error) {
proc := os.Getenv("HOST_PROC")
if proc == "" {
proc = "/proc"
}
memPath := filepath.Join(proc, strconv.Itoa(int(pid)), "statm")
contents, err := os.ReadFile(memPath)
if err != nil {
return nil, err
}
fields := strings.Split(string(contents), " ")
vms, err := strconv.ParseUint(fields[0], 10, 64)
if err != nil {
return nil, err
}
rss, err := strconv.ParseUint(fields[1], 10, 64)
if err != nil {
return nil, err
}
memInfo := &MemoryInfoStat{
RSS: rss * pageSize,
VMS: vms * pageSize,
}
return memInfo, nil
}