Merge pull request #115 from okmeter/fix_swap_freebsd
[freebsd] fix SwapMemory for hosts without swap
This commit is contained in:
commit
91e273aef0
|
@ -6,7 +6,7 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"errors"
|
||||||
"github.com/shirou/gopsutil/internal/common"
|
"github.com/shirou/gopsutil/internal/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -91,7 +91,6 @@ func SwapMemory() (*SwapMemoryStat, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var ret *SwapMemoryStat
|
|
||||||
for _, line := range strings.Split(string(out), "\n") {
|
for _, line := range strings.Split(string(out), "\n") {
|
||||||
values := strings.Fields(line)
|
values := strings.Fields(line)
|
||||||
// skip title line
|
// skip title line
|
||||||
|
@ -117,13 +116,13 @@ func SwapMemory() (*SwapMemoryStat, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = &SwapMemoryStat{
|
return &SwapMemoryStat{
|
||||||
Total: total_v,
|
Total: total_v,
|
||||||
Used: used_v,
|
Used: used_v,
|
||||||
Free: free_v,
|
Free: free_v,
|
||||||
UsedPercent: up_v,
|
UsedPercent: up_v,
|
||||||
}
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret, nil
|
return nil, errors.New("no swap devices found")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue