1
"""Deployment code for the monitor."""
5
from twisted.python.reflect import namedClass
7
from landscape.service import LandscapeService, run_landscape_service
8
from landscape.monitor.config import MonitorConfiguration
9
from landscape.monitor.monitor import Monitor
10
from landscape.broker.amp import (
11
BrokerClientProtocolFactory, RemoteBrokerConnector)
14
class MonitorService(LandscapeService):
16
The core Twisted Service which creates and runs all necessary monitoring
17
components when started.
20
service_name = Monitor.name
22
def __init__(self, config):
23
self.persist_filename = os.path.join(
24
config.data_path, "%s.bpickle" % self.service_name)
25
super(MonitorService, self).__init__(config)
26
self.plugins = self.get_plugins()
27
self.monitor = Monitor(self.reactor, self.config, self.persist,
28
persist_filename=self.persist_filename)
29
self.factory = BrokerClientProtocolFactory(object=self.monitor)
31
def get_plugins(self):
32
return [namedClass("landscape.monitor.%s.%s"
33
% (plugin_name.lower(), plugin_name))()
34
for plugin_name in self.config.plugin_factories]
36
def startService(self):
37
"""Start the monitor."""
38
super(MonitorService, self).startService()
40
def start_plugins(broker):
42
self.monitor.broker = broker
43
for plugin in self.plugins:
44
self.monitor.add(plugin)
45
return self.broker.register_client(self.service_name)
47
self.connector = RemoteBrokerConnector(self.reactor, self.config)
48
connected = self.connector.connect()
49
return connected.addCallback(start_plugins)
51
def stopService(self):
54
The monitor is flushed to ensure that things like persist databases
58
self.connector.disconnect()
59
super(MonitorService, self).stopService()
63
run_landscape_service(MonitorConfiguration, MonitorService, args)