1
"""Deployment code for the monitor."""
5
from twisted.python.reflect import namedClass
7
from landscape.deployment import (LandscapeService, Configuration,
9
from landscape.monitor.monitor import (MonitorPluginRegistry,
11
from landscape.broker.remote import (RemoteBroker,
12
DBusSignalToReactorTransmitter)
15
ALL_PLUGINS = ["ActiveProcessInfo", "ComputerInfo", "HardwareInventory",
16
"LoadAverage", "MemoryInfo", "MountInfo", "ProcessorInfo",
17
"Temperature", "PackageMonitor",
21
class MonitorConfiguration(Configuration):
22
"""Specialized configuration for the Landscape Monitor."""
24
def make_parser(self):
26
Specialize L{Configuration.make_parser}, adding many
27
monitor-specific options.
29
parser = super(MonitorConfiguration, self).make_parser()
31
parser.add_option("--monitor-plugins", metavar="PLUGIN_LIST",
32
help="Comma-delimited list of monitor plugins to "
33
"use. ALL means use all plugins.",
35
parser.add_option("--flush-interval", default=5*60, type="int",
37
help="The number of seconds between flushes.")
41
def plugin_factories(self):
42
if self.monitor_plugins == "ALL":
44
return [x.strip() for x in self.monitor_plugins.split(",")]
47
class MonitorService(LandscapeService):
49
The core Twisted Service which creates and runs all necessary monitoring
50
components when started.
53
service_name = "monitor"
55
def __init__(self, config):
56
self.persist_filename = os.path.join(config.data_path,
57
"%s.bpickle" % self.service_name)
58
super(MonitorService, self).__init__(config)
59
self.plugins = self.get_plugins()
61
def get_plugins(self):
62
return [namedClass("landscape.monitor.%s.%s"
63
% (plugin_name.lower(), plugin_name))()
64
for plugin_name in self.config.plugin_factories]
66
def startService(self):
67
super(MonitorService, self).startService()
69
# If this raises ServiceUnknownError, we should do something nice.
70
self.remote_broker = RemoteBroker(self.bus)
71
self.registry = MonitorPluginRegistry(self.reactor, self.remote_broker,
72
self.config, self.bus,
74
self.persist_filename)
75
self.dbus_service = MonitorDBusObject(self.bus, self.registry)
76
DBusSignalToReactorTransmitter(self.bus, self.reactor)
77
self.remote_broker.register_plugin(self.dbus_service.bus_name,
78
self.dbus_service.object_path)
80
for plugin in self.plugins:
81
self.registry.add(plugin)
83
self.flush_call_id = self.reactor.call_every(
84
self.config.flush_interval, self.registry.flush)
86
def stopService(self):
89
The monitor is flushed to ensure that things like persist
90
databases get saved to disk.
93
if self.flush_call_id:
94
self.reactor.cancel_call(self.flush_call_id)
95
self.flush_call_id = None
96
super(MonitorService, self).stopService()
100
run_landscape_service(MonitorConfiguration, MonitorService, args,
101
MonitorDBusObject.bus_name)