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:
Markus Mayer
2024-04-14 17:05:49 +02:00
committed by GitHub
parent 332ec8b86b
commit 5411999fd0

View File

@@ -71,7 +71,7 @@ def check_voltage():
def check_swap(): 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 = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE).communicate()[0]
swap = round(float(swap.decode("utf-8").replace(",", ".")), 1) swap = round(float(swap.decode("utf-8").replace(",", ".")), 1)