1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd. and others
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
14 LOG = logging.getLogger(__name__)
17 class MonitorProcess(basemonitor.BaseMonitor):
18 """docstring for MonitorApi"""
20 __monitor_type__ = "process"
23 host = self._context[self._config["host"]]
24 ip = host.get("ip", None)
25 user = host.get("user", "root")
26 key_filename = host.get("key_filename", "~/.ssh/id_rsa")
28 self.connection = ssh.SSH(user, ip, key_filename=key_filename)
29 self.connection.wait(timeout=600)
30 LOG.debug("ssh host success!")
31 self.check_script = self.get_script_fullpath(
32 "ha_tools/check_process_python.bash")
33 self.process_name = self._config["process_name"]
35 def monitor_func(self):
36 exit_status, stdout, stderr = self.connection.execute(
37 "/bin/sh -s {0}".format(self.process_name),
38 stdin=open(self.check_script, "r"))
39 if not stdout or int(stdout) <= 0:
40 LOG.info("the process (%s) is not running!" % self.process_name)
46 LOG.debug("the _result:%s" % self._result)
47 outage_time = self._result.get('outage_time', None)
48 max_outage_time = self._config["sla"]["max_recover_time"]
49 if outage_time > max_outage_time:
50 LOG.error("SLA failure: %f > %f" % (outage_time, max_outage_time))
56 def _test(): # pragma: no cover
60 "key_filename": "/root/.ssh/id_rsa"
62 context = {"node1": host}
65 'monitor_type': 'process',
66 'process_name': 'nova-api',
69 'sla': {'max_recover_time': 5}
71 monitor_configs.append(config)
73 p = basemonitor.MonitorMgr()
74 p.init_monitors(monitor_configs, context)
80 if __name__ == '__main__': # pragma: no cover