forked from ropod-project/component-monitoring
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
66 lines (52 loc) · 2.54 KB
/
main.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
59
60
61
62
63
64
65
66
#!/usr/bin/env python
import argparse
import multiprocessing
from component_monitoring.config.config_utils import ConfigUtils
from component_monitoring.monitor_manager import MonitorManager
from component_monitoring.utils.component_network import ComponentNetwork
import logging
from component_monitoring.storage.storage_manager import StorageManager
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Monitor component status',
epilog='EXAMPLE: python3 main.py 001 001')
parser.add_argument('config_file', type=str,
default='config/component_monitoring_config',
help='Path to a configuration file')
parser.add_argument('-d', '--debug', help='print debug output', action='store_true')
args = parser.parse_args()
# setup logging
if args.debug:
logging.basicConfig(level=logging.INFO)
else:
logging.basicConfig(level=logging.WARNING)
config_file_path = args.config_file
config_data = ConfigUtils.read_config(config_file_path)
robot_id = config_data['robot_id']
hw_monitor_config_dir = config_data['config_dirs']['hardware']
sw_monitor_config_dir = config_data['config_dirs']['software']
# we read the parameters of the hardware and software monitors
hw_monitor_config_params = ConfigUtils.get_config_params(hw_monitor_config_dir)
sw_monitor_config_params = ConfigUtils.get_config_params(sw_monitor_config_dir)
# we populate the parameters of the configuration utilities
# to simplify runtime access to the configuration data
ConfigUtils.config_data = config_data
ConfigUtils.hw_monitor_config_params = hw_monitor_config_params
ConfigUtils.sw_monitor_config_params = sw_monitor_config_params
storage_config_params = config_data['storage']
manager = multiprocessing.Manager()
monitors = manager.dict()
storage_manager = StorageManager(storage_config_params)
# we initialise a manager for the monitors that will continuously
# update the component status message
monitor_manager = MonitorManager(hw_monitor_config_params,
sw_monitor_config_params,
storage_manager)
# component_network = ComponentNetwork(config_file_path)
try:
monitor_manager.start()
storage_manager.start()
monitor_manager.join()
storage_manager.join()
except (KeyboardInterrupt, SystemExit):
monitor_manager.log_off()
print('Component monitors exiting')