本文整理汇总了Python中monitor.Monitor类的典型用法代码示例。如果您正苦于以下问题:Python Monitor类的具体用法?Python Monitor怎么用?Python Monitor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Monitor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, name, config_options):
Monitor.__init__(self, name, config_options)
try:
self.path = config_options["path"]
except:
raise RuntimeError("Required configuration fields missing")
self.params = ("svok %s" % self.path).split(" ")
示例2: __init__
def __init__(self, openoffice, interval, request_limit):
"""Expects to receive an object that implements the interfaces IApplication
and ILockable, the limit of request that the openoffice can receive and the
interval to check the object."""
Monitor.__init__(self, openoffice, interval)
Thread.__init__(self)
self.request_limit = request_limit
示例3: __init__
def __init__(self, name, config_options):
"""Initialise the class.
Change script path to /etc/rc.d/ to monitor base system services. If the
script path ends with /, the service name is appended."""
Monitor.__init__(self, name, config_options)
try:
service_name = config_options["service"]
except:
raise RuntimeError("Required configuration fields missing")
if 'path' in config_options:
script_path = config_options["path"]
else:
script_path = "/usr/local/etc/rc.d/"
if 'return_code' in config_options:
want_return_code = int(config_options["return_code"])
else:
want_return_code = 0
if service_name == "":
raise RuntimeError("missing service name")
if script_path == "":
raise RuntimeError("missing script path")
if script_path.endswith("/"):
script_path = script_path + service_name
self.script_path = script_path
self.service_name = service_name
self.want_return_code = want_return_code
# Check if we need a .sh (old-style RC scripts in FreeBSD)
if not os.path.isfile(self.script_path):
if os.path.isfile(self.script_path + ".sh"):
self.script_path = self.script_path + ".sh"
else:
raise RuntimeError("Script %s(.sh) does not exist" % self.script_path)
示例4: test_stop_personal_cloud
def test_stop_personal_cloud(self):
monitor = Monitor(self.personal_cloud)
print "try stop stop"
monitor.start()
# time.sleep(5)
monitor.stop()
示例5: __init__
def __init__(self, openoffice, interval, limit_memory_usage):
"""Expects to receive an object that implements the interfaces IApplication
and ILockable, the limit of memory usage that the openoffice can use and
the interval to check the object."""
Monitor.__init__(self, openoffice, interval)
Process.__init__(self)
self.limit = limit_memory_usage
示例6: __init__
def __init__(self, name, config_options):
"""
Note: We use -w/-t on Windows/POSIX to limit the amount of time we wait to 5 seconds.
This is to stop ping holding things up too much. A machine that can't ping back in <5s is
a machine in trouble anyway, so should probably count as a failure.
"""
Monitor.__init__(self, name, config_options)
try:
ping_ttl = config_options["ping_ttl"]
except:
ping_ttl = "5"
ping_ms = ping_ttl * 1000
platform = sys.platform
if platform in ['win32', 'cygwin']:
self.ping_command = "ping -n 1 -w " + ping_ms + " %s"
self.ping_regexp = "Reply from "
self.time_regexp = "Average = (?P<ms>\d+)ms"
elif platform.startswith('freebsd') or platform.startswith('darwin'):
self.ping_command = "ping -c1 -t" + ping_ttl + " %s"
self.ping_regexp = "bytes from"
self.time_regexp = "min/avg/max/stddev = [\d.]+/(?P<ms>[\d.]+)/"
elif platform.startswith('linux'):
self.ping_command = "ping -c1 -W" + ping_ttl + " %s"
self.ping_regexp = "bytes from"
self.time_regexp = "min/avg/max/stddev = [\d.]+/(?P<ms>[\d.]+)/"
else:
RuntimeError("Don't know how to run ping on this platform, help!")
try:
host = config_options["host"]
except:
raise RuntimeError("Required configuration fields missing")
if host == "":
raise RuntimeError("missing hostname")
self.host = host
示例7: poll
def poll(self):
"""
Measure current stats value and return new stats.
"""
Monitor.poll(self)
# create new, empty event
#
current = {
# the UTC timestamp when measurement was taken
u'timestamp': utcnow(),
# the effective last period in secods
u'last_period': self._last_period,
}
# FIXME: add ratio of ram usage
with open("/proc/meminfo") as f:
res = f.read()
new = res.split()
new_clean = [x.replace(":", "") for x in new if x != 'kB']
for i in range(0, len(new_clean), 2):
k = u'{}'.format(new_clean[i])
current[k] = int( new_clean[i + 1])
self._last_value = current
return succeed(self._last_value)
示例8: __init__
def __init__(self, name, config_options):
"""
Note: We use -w/-t on Windows/POSIX to limit the amount of time we wait to 5 seconds.
This is to stop ping holding things up too much. A machine that can't ping back in <5s is
a machine in trouble anyway, so should probably count as a failure.
"""
Monitor.__init__(self, name, config_options)
if self.is_windows(allow_cygwin=True):
self.ping_command = "ping -n 1 -w 5000 %s"
self.ping_regexp = "Reply from "
self.time_regexp = "Average = (?P<ms>\d+)ms"
else:
try:
ping_ttl = config_options["ping_ttl"]
except:
ping_ttl = "5"
self.ping_command = "ping -c1 -W2 -t"+ ping_ttl + " %s 2> /dev/null"
self.ping_regexp = "bytes from"
#XXX this regexp is only for freebsd at the moment; not sure about other platforms
#XXX looks like Linux uses this format too
self.time_regexp = "min/avg/max/stddev = [\d.]+/(?P<ms>[\d.]+)/"
try:
host = config_options["host"]
except:
raise RuntimeError("Required configuration fields missing")
if host == "":
raise RuntimeError("missing hostname")
self.host = host
示例9: main
def main():
# sleep(5) #added a sleep to avoid "Connection refused" or "404" errors
parser = argparse.ArgumentParser()
parser.add_argument('dir', help='the directory of the example')
args = parser.parse_args()
# locate config file
base_path = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)),"..","examples",args.dir,"config"))
config_file = os.path.join(base_path, "sdx_global.cfg")
# locate the monitor's flows configuration file
monitor_flows_file = os.path.join(base_path, "monitor_flows.cfg")
config = Config(config_file)
# start umbrella fabric manager
logger = util.log.getLogger('monitor')
logger.info('init')
try:
with file(monitor_flows_file) as f:
flows = json.load(f)
except IOError:
flows = None
logger.info("No file specified for initial flows.")
logger.info('REFMON client: ' + str(config.refmon["IP"]) + ' ' + str(config.refmon["Port"]))
client = RefMonClient(config.refmon["IP"], config.refmon["Port"], config.refmon["key"])
controller = Monitor(config, flows, client, logger)
logger.info('start')
controller.start()
示例10: random_tester
def random_tester():
monitor = Monitor()
while True:
user = random.randint(1,30)
if not monitor.check(str(user)):
print "malicious user detected"
time.sleep(0.05)
示例11: setup
def setup():
Monitor.get().start();
screen = Gdk.Screen.get_default();
for i in xrange(0, screen.get_n_monitors()):
# setup for each monitor
rect = screen.get_monitor_geometry(i);
config.config_monitor(i, rect);
示例12: __init__
def __init__(self, config, **args):
Monitor.__init__(self, config, **args)
self.critical = self.getconfig("critical")
self.warning = self.getconfig("warning")
self.ignoremissing = self.getconfig("ignoremissing", False)
self.func = self.getconfig("function", 'and')
示例13: update_NET_DESKTOP_GEOMETRY
def update_NET_DESKTOP_GEOMETRY(force=False):
global properties, xinerama
old_geom = properties["_NET_DESKTOP_GEOMETRY"]
old_xinerama = xinerama
time.sleep(1)
properties["_NET_DESKTOP_GEOMETRY"] = ptxcb.XROOT.get_desktop_geometry()
xinerama = ptxcb.connection.xinerama_get_screens()
if old_xinerama != xinerama or force:
if not force and len(old_xinerama) == len(xinerama):
for mon in Workspace.iter_all_monitors():
mid = mon.id
mon.refresh_bounds(
xinerama[mid]["x"], xinerama[mid]["y"], xinerama[mid]["width"], xinerama[mid]["height"]
)
mon.calculate_workarea()
else:
for mon in Workspace.iter_all_monitors():
for tiler in mon.tilers:
tiler.destroy()
for wid in Window.WINDOWS.keys():
Window.remove(wid)
for wsid in Workspace.WORKSPACES.keys():
Monitor.remove(wsid)
Workspace.remove(wsid)
reset_properties()
load_properties()
示例14: __init__
def __init__(self, openoffice, interval, sleeping_time):
"""Expects to receive an object that implements the interfaces IApplication
and ILockable, the limit of memory usage that the openoffice can use and
the interval to check the object."""
Monitor.__init__(self, openoffice, interval)
Thread.__init__(self)
self.sleeping_time = sleeping_time
self._touched_at = time()
示例15: monitor_torrent
def monitor_torrent():
"""
Monitoring remote transmission status
"""
print (green('Monitoring remote transmission status.'))
monitor = Monitor()
monitor.start()
monitor.join()