Only handle virtual memory when specifically requested

pull/1651/head
Dylan Myers 1 year ago
parent 3bf34ce7fb
commit a0bbccacc6

@ -12,7 +12,7 @@ import (
) )
func VirtualMemoryWithContext(ctx context.Context) (*VirtualMemoryStat, error) { func VirtualMemoryWithContext(ctx context.Context) (*VirtualMemoryStat, error) {
vmem, swap, err := callSVMon(ctx) vmem, swap, err := callSVMon(ctx, true)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -25,7 +25,7 @@ func VirtualMemoryWithContext(ctx context.Context) (*VirtualMemoryStat, error) {
} }
func SwapMemoryWithContext(ctx context.Context) (*SwapMemoryStat, error) { func SwapMemoryWithContext(ctx context.Context) (*SwapMemoryStat, error) {
_, swap, err := callSVMon(ctx) _, swap, err := callSVMon(ctx, false)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -35,7 +35,7 @@ func SwapMemoryWithContext(ctx context.Context) (*SwapMemoryStat, error) {
return swap, nil return swap, nil
} }
func callSVMon(ctx context.Context) (*VirtualMemoryStat, *SwapMemoryStat, error) { func callSVMon(ctx context.Context, virt bool) (*VirtualMemoryStat, *SwapMemoryStat, error) {
out, err := invoke.CommandWithContext(ctx, "svmon", "-G") out, err := invoke.CommandWithContext(ctx, "svmon", "-G")
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
@ -45,7 +45,7 @@ func callSVMon(ctx context.Context) (*VirtualMemoryStat, *SwapMemoryStat, error)
vmem := &VirtualMemoryStat{} vmem := &VirtualMemoryStat{}
swap := &SwapMemoryStat{} swap := &SwapMemoryStat{}
for _, line := range strings.Split(string(out), "\n") { for _, line := range strings.Split(string(out), "\n") {
if strings.HasPrefix(line, "memory") { if virt && strings.HasPrefix(line, "memory") {
p := strings.Fields(line) p := strings.Fields(line)
if len(p) > 2 { if len(p) > 2 {
if t, err := strconv.ParseUint(p[1], 10, 64); err == nil { if t, err := strconv.ParseUint(p[1], 10, 64); err == nil {

Loading…
Cancel
Save