diff options
author | 2016-07-05 01:56:55 +0000 | |
---|---|---|
committer | 2016-07-05 01:56:55 +0000 | |
commit | 588631b53537b71330bd21e4f9aebb9de429b2a3 (patch) | |
tree | 328b3437d8a66494469e358d3bf8e8378a1f4d84 /yardstick | |
parent | d51cbf72b8fb2e5c6acc06248919b1401d09c853 (diff) | |
parent | 0c3748240cfb2bce7d8727dd0283468e44d57ae9 (diff) |
Merge "Creating a generic monitor"
Diffstat (limited to 'yardstick')
3 files changed, 94 insertions, 1 deletions
diff --git a/yardstick/benchmark/scenarios/availability/monitor/basemonitor.py b/yardstick/benchmark/scenarios/availability/monitor/basemonitor.py index 983c3a3ac..d26c99c75 100644 --- a/yardstick/benchmark/scenarios/availability/monitor/basemonitor.py +++ b/yardstick/benchmark/scenarios/availability/monitor/basemonitor.py @@ -12,6 +12,7 @@ import multiprocessing import time import os import yardstick.common.utils as utils +import yaml LOG = logging.getLogger(__name__) @@ -32,9 +33,16 @@ class MonitorMgr(object): monitor_type = monitor_cfg["monitor_type"] monitor_cls = BaseMonitor.get_monitor_cls(monitor_type) monitor_ins = monitor_cls(monitor_cfg, context) - + if "key" in monitor_cfg: + monitor_ins.key = monitor_cfg["key"] self._monitor_list.append(monitor_ins) + def __getitem__(self, item): + for obj in self._monitor_list: + if obj.key == item: + return obj + raise KeyError("No such monitor instance of key - %s" % item) + def start_monitors(self): for _monotor_instace in self._monitor_list: _monotor_instace.start_monitor() @@ -52,8 +60,12 @@ class MonitorMgr(object): class BaseMonitor(multiprocessing.Process): """docstring for BaseMonitor""" + monitor_cfgs = {} def __init__(self, config, context): + if not BaseMonitor.monitor_cfgs: + with open(monitor_conf_path) as stream: + BaseMonitor.monitor_cfgs = yaml.load(stream) multiprocessing.Process.__init__(self) self._config = config self._context = context diff --git a/yardstick/benchmark/scenarios/availability/monitor/monitor_general.py b/yardstick/benchmark/scenarios/availability/monitor/monitor_general.py new file mode 100644 index 000000000..515514c29 --- /dev/null +++ b/yardstick/benchmark/scenarios/availability/monitor/monitor_general.py @@ -0,0 +1,70 @@ +############################################################################## +# Copyright (c) 2016 Juan Qiu and others +# juan_ qiu@tongji.edu.cn +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +import logging +import yardstick.ssh as ssh + +import basemonitor as basemonitor +from yardstick.benchmark.scenarios.availability.util import buildshellparams + + +LOG = logging.getLogger(__name__) + + +class GeneralMonitor(basemonitor.BaseMonitor): + """docstring for MonitorApi""" + + __monitor_type__ = "general-monitor" + + def setup(self): + host = self._context[self._config["host"]] + ip = host.get("ip", None) + user = host.get("user", "root") + key_filename = host.get("key_filename", "~/.ssh/id_rsa") + self.key = self._config["key"] + self.monitor_type = self._config["monitor_type"] + + if "parameter" in self._config: + parameter = self._config['parameter'] + str = buildshellparams(parameter) + l = list(item for item in parameter.values()) + self.cmd_param = str.format(*l) + + self.monitor_cfg = basemonitor.BaseMonitor.monitor_cfgs.get(self.key) + self.monitor_script = self.get_script_fullpath( + self.monitor_cfg['monitor_script']) + self.connection = ssh.SSH(user, ip, key_filename=key_filename) + self.connection.wait(timeout=600) + LOG.debug("ssh host success!") + + def monitor_func(self): + if "parameter" in self._config: + exit_status, stdout, stderr = self.connection.execute( + self.cmd_param, + stdin=open(self.monitor_script, "r")) + else: + exit_status, stdout, stderr = self.connection.execute( + "/bin/bash -s ", + stdin=open(self.monitor_script, "r")) + + if exit_status: + return False + return True + + def verify_SLA(self): + LOG.debug("the _result:%s" % self._result) + outage_time = self._result.get('outage_time', None) + max_outage_time = self._config["sla"]["max_recover_time"] + if outage_time is None: + LOG.error("There is no outage_time in monitor result.") + return False + if outage_time > max_outage_time: + LOG.error("SLA failure: %f > %f" % (outage_time, max_outage_time)) + return False + else: + return True diff --git a/yardstick/benchmark/scenarios/availability/monitor_conf.yaml b/yardstick/benchmark/scenarios/availability/monitor_conf.yaml new file mode 100644 index 000000000..9efceed88 --- /dev/null +++ b/yardstick/benchmark/scenarios/availability/monitor_conf.yaml @@ -0,0 +1,11 @@ +--- +# sample config file for ha test +# +schema: "yardstick:task:0.1" + +process_status: + monitor_script: ha_tools/check_process_python.bash +nova_image_list: + monitor_script: ha_tools/nova_image_list.bash +service_status: + monitor_script: ha_tools/check_service.bash |