balena-io-examples / internetspeedtest

Log your internet download, upload and ping metrics ti influxDB, and Grafana it. Grafana all the things!
GNU General Public License v3.0
56 stars 18 forks source link

Speedtest hangs up #11

Closed cornflakes closed 2 years ago

cornflakes commented 3 years ago

I've tried to use this app on a couple of devices, one RaspberryPi 3b+ 2015 and two different RaspberryPi 3b+ 2017 all of them stalls after a little while with only 4ish measurements with mqtt, influxdb, connector and dashboard running, speedtest is also status running, but it does not make any measurements and terminal does not work.

I can get it up and running again by either restarting the devices or sometimes the speedtest service.

cornflakes commented 3 years ago

Screenshot 2021-02-10 at 11 28 27

phil-d-wilson commented 3 years ago

Hey @cornflakes - I'm not seeing this with a Pi4. I'll deploy it to a 3B+ and see if I can recreate.

phil-d-wilson commented 3 years ago

@cornflakes - I can't recreate so far. I'll leave it running, but so far it's running fine on a 3B+:

image

phil-d-wilson commented 3 years ago

I've upped the frequency, and it's happily banging out test scores. I'm not sure how to recreate this.

cornflakes commented 3 years ago

I'll try using a clean version of the application and see if that does anything...

cornflakes commented 3 years ago

I still have problems... Screenshot 2021-02-11 at 08 04 33 Screenshot 2021-02-11 at 08 04 48

This is from a completely fresh deploy done with the "Deploy with balena"-button Only setting changed was the interval set to 1200 instead of 3600

cornflakes commented 3 years ago

I've found something inspecting the logs of the speedtest container.

It seems the python script isn't very resilient towards errors:

Traceback (most recent call last):
  File "speedtest.py", line 35, in <module>
    result = speedtest.test()
  File "speedtest.py", line 18, in test
    print ("Timestamp = " + str(result['timestamp']))
KeyError: 'timestamp'
[2021-02-10 17:49:57.541] [error] Trying to get interface information on non-initialized socket.
[2021-02-10 17:50:13.070] [error] Configuration - Couldn't resolve host name (HostNotFoundException)
[2021-02-10 17:50:13.072] [error] Configuration - Cannot retrieve configuration document (0)
[2021-02-10 17:50:13.073] [error] ConfigurationError - Could not retrieve or read configuration (Configuration)
[2021-02-10 17:50:13.074] [error] ConfigurationError - Could not retrieve or read configuration (Configuration)
{"type":"log","timestamp":"2021-02-10T17:50:13Z","message":"Configuration - Could not retrieve or read configuration (ConfigurationError)","level":"error"}
Traceback (most recent call last):
  File "speedtest.py", line 35, in <module>
    result = speedtest.test()
  File "speedtest.py", line 17, in test
    result = json.loads(response[0])
  File "/usr/local/lib/python3.7/json/__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.7/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python3.7/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
[2021-02-10 17:50:30.941] [error] Trying to get interface information on non-initialized socket.

So the error could indicate that I lose my connection to the internet sometimes...

cornflakes commented 3 years ago

I've tried using a poor mans try/except around the test and haven't had any issues so far (looking at 10+ readings)

I think the answer here would be better error handling.

phil-d-wilson commented 3 years ago

@cornflakes great! Feel free to PR any features, improvements, fixes you come up with!