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 ##############################################################################
9 from __future__ import absolute_import
11 import yardstick.ssh as ssh
13 from yardstick.benchmark.scenarios.availability.monitor import basemonitor
14 from yardstick.benchmark.scenarios.availability.util import buildshellparams
17 LOG = logging.getLogger(__name__)
20 class GeneralMonitor(basemonitor.BaseMonitor):
21 """docstring for MonitorApi"""
23 __monitor_type__ = "general-monitor"
26 host = self._context[self._config["host"]]
27 ip = host.get("ip", None)
28 user = host.get("user", "root")
29 ssh_port = host.get("ssh_port", ssh.DEFAULT_PORT)
30 key_filename = host.get("key_filename", "~/.ssh/id_rsa")
31 self.key = self._config["key"]
32 self.monitor_key = self._config["monitor_key"]
33 self.monitor_type = self._config["monitor_type"]
35 if "parameter" in self._config:
36 parameter = self._config['parameter']
37 str = buildshellparams(parameter)
38 l = list(item for item in parameter.values())
39 self.cmd_param = str.format(*l)
41 self.monitor_cfg = basemonitor.BaseMonitor.monitor_cfgs.get(
43 self.monitor_script = self.get_script_fullpath(
44 self.monitor_cfg['monitor_script'])
45 self.connection = ssh.SSH(user, ip, key_filename=key_filename,
47 self.connection.wait(timeout=600)
48 LOG.debug("ssh host success!")
50 def monitor_func(self):
51 if "parameter" in self._config:
52 with open(self.monitor_script, "r") as stdin_file:
53 exit_status, stdout, stderr = self.connection.execute(
57 with open(self.monitor_script, "r") as stdin_file:
58 exit_status, stdout, stderr = self.connection.execute(
67 LOG.debug("the _result:%s", self._result)
68 outage_time = self._result.get('outage_time', None)
69 max_outage_time = self._config["sla"]["max_outage_time"]
70 if outage_time is None:
71 LOG.error("There is no outage_time in monitor result.")
73 if outage_time > max_outage_time:
74 LOG.error("SLA failure: %f > %f", outage_time, max_outage_time)