Fix division by zero error when no Swap available (#92)
Resolves hjelev/rpi-mqtt-monitor#11 Co-authored-by: Masoko <jeleff@gmail.com>
This commit is contained in:
@@ -71,7 +71,7 @@ def check_voltage():
|
||||
|
||||
|
||||
def check_swap():
|
||||
full_cmd = "free | grep -i swap | awk 'NR == 1 {print $3/$2*100}'"
|
||||
full_cmd = "free | grep -i swap | awk 'NR == 1 {if($2 > 0) {print $3/$2*100} else {print 0}}'"
|
||||
swap = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE).communicate()[0]
|
||||
swap = round(float(swap.decode("utf-8").replace(",", ".")), 1)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user