-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathconfig_loader.py
More file actions
77 lines (57 loc) · 2.44 KB
/
config_loader.py
File metadata and controls
77 lines (57 loc) · 2.44 KB
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
67
68
69
70
71
72
73
74
75
76
77
from .api_request import APIRequest
from .utils import timestamp
class ConfigLoader(object):
LOAD_DELAY = 2
LOAD_INTERVAL = 120
def __init__(self, agent):
self.agent = agent
self.load_timer = None
self.last_load_ts = 0
def start(self):
if self.agent.get_option('auto_profiling'):
self.load_timer = self.agent.schedule(self.LOAD_DELAY, self.LOAD_INTERVAL, self.load)
def stop(self):
if self.load_timer:
self.load_timer.cancel()
self.load_timer = None
def load(self, with_interval=False):
now = timestamp()
if with_interval and self.last_load_ts > now - self.LOAD_INTERVAL:
return
self.last_load_ts = now;
try:
api_request = APIRequest(self.agent)
config = api_request.post('config', {})
# agent_enabled yes|no
if 'agent_enabled' in config:
self.agent.config.set_agent_enabled(config['agent_enabled'] == 'yes')
else:
self.agent.config.set_agent_enabled(False)
# profiling_disabled yes|no
if 'profiling_disabled' in config:
self.agent.config.set_profiling_disabled(config['profiling_disabled'] == 'yes')
else:
self.agent.config.set_profiling_disabled(False)
if self.agent.config.is_agent_enabled() and not self.agent.config.is_profiling_disabled():
self.agent.cpu_reporter.start()
self.agent.allocation_reporter.start()
self.agent.block_reporter.start()
self.agent.tf_reporter.start()
else:
self.agent.cpu_reporter.stop()
self.agent.allocation_reporter.stop()
self.agent.block_reporter.stop()
self.agent.tf_reporter.stop()
if self.agent.config.is_agent_enabled():
self.agent.error_reporter.start()
self.agent.span_reporter.start()
self.agent.process_reporter.start()
self.agent.log('Agent activated')
else:
self.agent.error_reporter.stop()
self.agent.span_reporter.stop()
self.agent.process_reporter.stop()
self.agent.log('Agent deactivated')
except Exception:
self.agent.log('Error loading config')
self.agent.exception()