hjelev / rpi-mqtt-monitor

Raspberry Pi MQTT Monitor gathers system information and sends it to a MQTT server.
GNU General Public License v3.0
176 stars 42 forks source link

Division by Zero #11

Closed sonydogg closed 1 year ago

sonydogg commented 1 year ago

Tried both manually installing and using the script. Fails to run with a divide by zero error. Thoughts?

awk: cmd. line:1: (FILENAME=- FNR=3) fatal: division by zero attempted Traceback (most recent call last): File "/home//rpi-cpu2mqtt.py", line 249, in swap = check_swap() File "/home//rpi-cpu2mqtt.py", line 51, in check_swap swap = round(float(swap.decode("utf-8").replace(",", ".")), 1) ValueError: could not convert string to float: ''

hjelev commented 1 year ago

Hi, What hardware and OS are you using?

If you change this line:

File "/home//rpi-cpu2mqtt.py", line 249, in swap = check_swap()

to swap = 0

You should get the script working w/o the swap usage part, it will always show 0

This swap function is executing this via shell: free -t | awk 'NR == 3 {print $3/$2*100}'

reading the output and converting it from string to float in order to round it up. If you are not happy to disable swap, provide the output of this shell command and I'll be able to troubleshoot further.

sonydogg commented 1 year ago

I'm running Ubuntu 2204 on Raspberry PI 4. Curiously the error went away. Couldn't tell you what I did. Thank you for responding.