Skip to content

Commit

Permalink
Merge pull request #50 from plaintextpackets/issue_3_speedtest_issues
Browse files Browse the repository at this point in the history
Issue 3 speedtest issues
  • Loading branch information
plaintextpackets committed May 22, 2024
2 parents d638071 + ab7ebcb commit 9103176
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
1 change: 1 addition & 0 deletions helpers/network_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def netprobe_speedtest(self):

def collect(self):

self.speedtest_stats = {"download": None, "upload": None}
self.netprobe_speedtest()

results = json.dumps({
Expand Down
2 changes: 1 addition & 1 deletion netprobe.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

cache.redis_write('netprobe',json.dumps(stats),cache_interval)

logger.info(f"Stats successfully written to Redis from device ID for Netprobe")
#logger.info(f"Stats successfully written to Redis from device ID for Netprobe")

except Exception as e:

Expand Down
49 changes: 27 additions & 22 deletions netprobe_speedtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,41 @@

logger = setup_logging("logs/speedtest.log")

while True:
if speedtest_enabled == True:

try:
stats = collector.collect()
current_time = datetime.now()
while True:

try:
stats = collector.collect()
current_time = datetime.now()

except Exception as e:
print("Error running speedtest")
logger.error("Error running speedtest")
logger.error(e)
time.sleep(speedtest_interval) # Pause before retrying
continue
except Exception as e:
print("Error running speedtest")
logger.error("Error running speedtest")
logger.error(e)
time.sleep(speedtest_interval) # Pause before retrying
continue

# Connect to Redis
# Connect to Redis

try:
try:

cache = RedisConnect()
cache = RedisConnect()

# Save Data to Redis
# Save Data to Redis

cache_interval = speedtest_interval*2 # Set the redis cache 2x longer than the speedtest interval
cache_interval = speedtest_interval*2 # Set the redis cache 2x longer than the speedtest interval

cache.redis_write('speedtest',json.dumps(stats),cache_interval)
cache.redis_write('speedtest',json.dumps(stats),cache_interval)

logger.info(f"Stats successfully written to Redis for Speed Test")
logger.info(f"Stats successfully written to Redis for Speed Test")

except Exception as e:
except Exception as e:

logger.error("Could not connect to Redis")
logger.error(e)

time.sleep(speedtest_interval)
logger.error("Could not connect to Redis")
logger.error(e)

time.sleep(speedtest_interval)

else:
exit()

0 comments on commit 9103176

Please sign in to comment.