-
Notifications
You must be signed in to change notification settings - Fork 6
/
speedmon.py
49 lines (37 loc) · 1.62 KB
/
speedmon.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
import os
import sys
import time
from speedmon.common.exceptions import SpeedtestInstallFailure
from speedmon.common.logging.log import configure_logger
from speedmon.common.speedtest_cli_validation import check_for_speedtest_cli, attempt_to_install_speedtest_cli
from speedmon.common.utils import run_speedtest_with_servers, \
run_speedtest_with_default_server, run_one_off_args
from speedmon.config.config_manager import ConfigManager
from speedmon.storage.storage_builder import init_storage_handlers, \
filter_dead_storage_handlers
log = configure_logger(name='speedmon')
if __name__ == '__main__':
config = None
if os.getenv('SPEEDTEST_CONFIG', None):
config = ConfigManager(config_file=os.getenv('SPEEDTEST_CONFIG'))
else:
config = ConfigManager()
if not check_for_speedtest_cli():
log.error('Unable to find Speedtest CLI. Attempting to install')
try:
attempt_to_install_speedtest_cli()
except SpeedtestInstallFailure:
sys.exit(1)
for arg in ['--accept-license', '--accept-gdpr']:
run_one_off_args(arg)
storage_handlers = init_storage_handlers(ini=config.loaded_config)
storage_handlers = list(filter(filter_dead_storage_handlers, storage_handlers))
if not storage_handlers:
log.error('No active storage handlers available ')
while True:
if config.servers:
run_speedtest_with_servers(storage_handlers, config.servers)
else:
run_speedtest_with_default_server(storage_handlers)
log.debug('Waiting %s seconds until next test', config.delay)
time.sleep(config.delay)