Bug fixed division 0 in SwapMemory()
This commit is contained in:
parent
35c5899e02
commit
2dd4a033d6
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue