-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_monitoring.py
49 lines (40 loc) · 1.36 KB
/
run_monitoring.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 logging
import argparse
import yaml
import threading
from monitor.Checker import Checker
from monitor.KafkaFactory import getKafkaProducer
from utils import initLogger
def processItem(c: Checker, l: logging):
l.info('started thread {}'.format(c.websiteUrl))
while True:
c.process()
c.wait()
def runMonitoring(config_file_location):
with open(config_file_location, 'r') as f:
config = yaml.load(f, Loader=yaml.SafeLoader)
logger = initLogger('monitor', level=config['log_level'])
threads = []
for w in config['websites']:
x = threading.Thread(
name='thread {}'.format(w['url']),
target=processItem,
args=(
Checker(
website=w,
kafka_producer=getKafkaProducer(
kafka_connect=config['kafka_connect']
),
kafka_topic=config['kafka_connect']['topic'],
default_interval=config['check_every_seconds_default']
),
logger
)
)
threads.append(x)
x.start()
if __name__ == '__main__':
a = argparse.ArgumentParser(description='website checker unit')
a.add_argument('--config', help='config file name', default='config/config.yml')
args = a.parse_args()
runMonitoring(args.config)