shirou_gopsutil/mem/mem_aix.go

59 lines
1.6 KiB
Go
Raw Normal View History

2021-11-09 21:14:54 +08:00
// +build aix
package mem
import (
2021-12-23 05:46:33 +08:00
"context"
2021-11-09 21:14:54 +08:00
2021-12-23 05:46:33 +08:00
"github.com/power-devops/perfstat"
2021-11-09 21:14:54 +08:00
)
func VirtualMemory() (*VirtualMemoryStat, error) {
2021-12-23 05:46:33 +08:00
return VirtualMemoryWithContext(context.Background())
2021-11-09 21:14:54 +08:00
}
func VirtualMemoryWithContext(ctx context.Context) (*VirtualMemoryStat, error) {
2021-12-23 05:46:33 +08:00
m, err := perfstat.MemoryTotalStat()
if err != nil {
return nil, err
}
pagesize := uint64(4096)
ret := VirtualMemoryStat{
Total: uint64(m.RealTotal) * pagesize,
Available: uint64(m.RealAvailable) * pagesize,
Free: uint64(m.RealFree) * pagesize,
Used: uint64(m.RealInUse) * pagesize,
UsedPercent: 100 * float64(m.RealInUse) / float64(m.RealTotal),
Active: uint64(m.VirtualActive) * pagesize,
SwapTotal: uint64(m.PgSpTotal) * pagesize,
SwapFree: uint64(m.PgSpFree) * pagesize,
}
return &ret, nil
2021-11-09 21:14:54 +08:00
}
func SwapMemory() (*SwapMemoryStat, error) {
2021-12-23 05:46:33 +08:00
return SwapMemoryWithContext(context.Background())
2021-11-09 21:14:54 +08:00
}
func SwapMemoryWithContext(ctx context.Context) (*SwapMemoryStat, error) {
2021-12-23 05:46:33 +08:00
m, err := perfstat.MemoryTotalStat()
if err != nil {
return nil, err
}
pagesize := uint64(4096)
swapUsed := uint64(m.PgSpTotal-m.PgSpFree-m.PgSpRsvd) * pagesize
swapTotal := uint64(m.PgSpTotal) * pagesize
ret := SwapMemoryStat{
Total: swapTotal,
Free: uint64(m.PgSpFree) * pagesize,
Used: swapUsed,
UsedPercent: float64(100*swapUsed) / float64(swapTotal),
Sin: uint64(m.PgSpIn),
Sout: uint64(m.PgSpOut),
PgIn: uint64(m.PageIn),
PgOut: uint64(m.PageOut),
PgFault: uint64(m.PageFaults),
}
return &ret, nil
2021-11-09 21:14:54 +08:00
}