Skip to content

Commit

Permalink
memory: silently ignore type=virtual for now
Browse files Browse the repository at this point in the history
pull request openened to expose those values:
shirou/gopsutil#1588
  • Loading branch information
sni committed Jan 26, 2024
1 parent 8073170 commit 11b22ca
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pkg/snclient/check_memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ func (l *CheckMemory) Check(_ context.Context, _ *Agent, check *CheckData, _ []A
return nil, fmt.Errorf("fetching virtual memory failed: %s", err.Error())
}

swap, err := mem.SwapMemory()
if err != nil {
return nil, fmt.Errorf("fetching swap failed: %s", err.Error())
}

if physical.Total == 0 {
return nil, fmt.Errorf("total physical memory is zero")
}
Expand All @@ -87,9 +82,15 @@ func (l *CheckMemory) Check(_ context.Context, _ *Agent, check *CheckData, _ []A
case "physical":
l.addMemType(check, "physical", physical.Used, physical.Free, physical.Total)
case "committed":
swap, err := mem.SwapMemory()
if err != nil {
return nil, fmt.Errorf("fetching swap failed: %s", err.Error())
}
if swap.Total > 0 {
l.addMemType(check, "committed", swap.Used, swap.Free, swap.Total)
}
case "virtual":
// not supported by gopsutil module yet
default:
return nil, fmt.Errorf("unknown type, please use 'physical' or 'committed'")
}
Expand Down

0 comments on commit 11b22ca

Please sign in to comment.