-
Notifications
You must be signed in to change notification settings - Fork 121
/
netprobe.py
58 lines (38 loc) · 1.52 KB
/
netprobe.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Netprobe Service
import time
from helpers.network_helper import NetworkCollector
from helpers.http_helper import *
from helpers.redis_helper import *
from config import Config_Netprobe
from datetime import datetime
from helpers.logging_helper import *
if __name__ == '__main__':
# Global Variables
probe_interval = Config_Netprobe.probe_interval
probe_count = Config_Netprobe.probe_count
sites = Config_Netprobe.sites
dns_test_site = Config_Netprobe.dns_test_site
nameservers_external = Config_Netprobe.nameservers
collector = NetworkCollector(sites,probe_count,dns_test_site,nameservers_external)
# Logging Config
logger = setup_logging("logs/netprobe.log")
while True:
try:
stats = collector.collect()
current_time = datetime.now()
except Exception as e:
print("Error testing network")
logger.error("Error testing network")
logger.error(e)
continue
# Connect to Redis
try:
cache = RedisConnect()
# Save Data to Redis
cache_interval = probe_interval + 15 # Set the redis cache TTL slightly longer than the probe interval
cache.redis_write('netprobe',json.dumps(stats),cache_interval)
#logger.info(f"Stats successfully written to Redis from device ID for Netprobe")
except Exception as e:
logger.error("Could not connect to Redis")
logger.error(e)
time.sleep(probe_interval)