1 ##############################################################################
2 # Copyright (c) 2016 Juan Qiu and others
3 # juan_ qiu@tongji.edu.cn
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
10 import yardstick.ssh as ssh
12 import basemonitor as basemonitor
13 from yardstick.benchmark.scenarios.availability.util import buildshellparams
16 LOG = logging.getLogger(__name__)
19 class GeneralMonitor(basemonitor.BaseMonitor):
20 """docstring for MonitorApi"""
22 __monitor_type__ = "general-monitor"
25 host = self._context[self._config["host"]]
26 ip = host.get("ip", None)
27 user = host.get("user", "root")
28 key_filename = host.get("key_filename", "~/.ssh/id_rsa")
29 self.key = self._config["key"]
30 self.monitor_key = self._config["monitor_key"]
31 self.monitor_type = self._config["monitor_type"]
33 if "parameter" in self._config:
34 parameter = self._config['parameter']
35 str = buildshellparams(parameter)
36 l = list(item for item in parameter.values())
37 self.cmd_param = str.format(*l)
39 self.monitor_cfg = basemonitor.BaseMonitor.monitor_cfgs.get(
41 self.monitor_script = self.get_script_fullpath(
42 self.monitor_cfg['monitor_script'])
43 self.connection = ssh.SSH(user, ip, key_filename=key_filename)
44 self.connection.wait(timeout=600)
45 LOG.debug("ssh host success!")
47 def monitor_func(self):
48 if "parameter" in self._config:
49 exit_status, stdout, stderr = self.connection.execute(
51 stdin=open(self.monitor_script, "r"))
53 exit_status, stdout, stderr = self.connection.execute(
55 stdin=open(self.monitor_script, "r"))
62 LOG.debug("the _result:%s" % self._result)
63 outage_time = self._result.get('outage_time', None)
64 max_outage_time = self._config["sla"]["max_outage_time"]
65 if outage_time is None:
66 LOG.error("There is no outage_time in monitor result.")
68 if outage_time > max_outage_time:
69 LOG.error("SLA failure: %f > %f" % (outage_time, max_outage_time))