Bug fixed division 0 in SwapMemory()

This commit is contained in:
Gronpipmaster 2014-09-10 01:23:12 +07:00
parent 35c5899e02
commit 2dd4a033d6
1 changed files with 6 additions and 1 deletions

View File

@ -55,7 +55,12 @@ func SwapMemory() (*SwapMemoryStat, error) {
Free: uint64(sysinfo.Freeswap), Free: uint64(sysinfo.Freeswap),
} }
ret.Used = ret.Total - ret.Free ret.Used = ret.Total - ret.Free
ret.UsedPercent = float64(ret.Total-ret.Free) / float64(ret.Total) * 100.0 //check Infinity
if ret.Total != 0 {
ret.UsedPercent = float64(ret.Total-ret.Free) / float64(ret.Total) * 100.0
} else {
ret.UsedPercent = 0
}
return ret, nil return ret, nil
} }