You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
staros/memory_unix.go

25 lines
622 B
Go

//+build linux
package staros
import "syscall"
// Memory 系统内存信息
func Memory() (MemStatus, error) {
var mem MemStatus
ram := new(syscall.Sysinfo_t)
if err := syscall.Sysinfo(ram); err != nil {
return mem, err
}
mem.All = uint64(ram.Totalram)
mem.BuffCache = uint64(ram.Bufferram)
mem.Free = uint64(ram.Freeram)
mem.Shared = uint64(ram.Sharedram)
mem.Available = uint64(ram.Freeram + ram.Sharedram + ram.Bufferram)
mem.SwapAll = uint64(ram.Totalswap)
mem.SwapFree = uint64(ram.Freeswap)
mem.SwapUsed = uint64(mem.SwapAll - mem.SwapFree)
mem.Used = uint64(mem.All - mem.Free)
return mem, nil
}