1 ##############################################################################
2 # Copyright (c) 2017 Huan Li and others
3 # lihuansse@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 from __future__ import absolute_import
14 from yardstick.benchmark.scenarios.availability.monitor import basemonitor
16 LOG = logging.getLogger(__name__)
19 class MultiMonitor(basemonitor.BaseMonitor):
21 __monitor_type__ = "multi-monitor"
23 def __init__(self, config, context):
24 super(MultiMonitor, self).__init__(config, context)
27 monitor_type = self._config["monitor_type"]
28 monitor_cls = basemonitor.BaseMonitor.get_monitor_cls(monitor_type)
30 monitor_number = self._config.get("monitor_number", 1)
31 for i in range(monitor_number):
32 monitor_ins = monitor_cls(self._config, self._context)
33 self.monitors.append(monitor_ins)
35 def start_monitor(self):
36 for monitor in self.monitors:
37 monitor.start_monitor()
39 def wait_monitor(self):
40 for monitor in self.monitors:
41 monitor.wait_monitor()
44 first_outage = time.time()
47 for monitor in self.monitors:
48 monitor_result = monitor.result()
49 monitor_first_outage = monitor_result.get('first_outage', 0)
50 monitor_last_outage = monitor_result.get('last_outage', 0)
52 if monitor_first_outage == 0 or monitor_last_outage == 0:
55 if monitor_first_outage < first_outage:
56 first_outage = monitor_first_outage
58 if monitor_last_outage > last_outage:
59 last_outage = monitor_last_outage
61 last_outage - first_outage if last_outage > first_outage else 0
63 LOG.debug("outage_time is: %f", outage_time)
66 if "max_outage_time" in self._config["sla"]:
67 max_outage_time = self._config["sla"]["max_outage_time"]
68 elif "max_recover_time" in self._config["sla"]:
69 max_outage_time = self._config["sla"]["max_recover_time"]
71 raise RuntimeError("monitor max_outage_time config is not found")
73 if outage_time > max_outage_time:
74 LOG.error("SLA failure: %f > %f", outage_time, max_outage_time)