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, data):
24 super(MultiMonitor, self).__init__(config, context, data)
27 self.monitor_data = data
28 monitor_type = self._config["monitor_type"]
29 monitor_cls = basemonitor.BaseMonitor.get_monitor_cls(monitor_type)
31 monitor_number = self._config.get("monitor_number", 1)
32 for i in range(monitor_number):
33 monitor_ins = monitor_cls(self._config, self._context,
35 self.monitors.append(monitor_ins)
37 def start_monitor(self):
38 for monitor in self.monitors:
39 monitor.start_monitor()
41 def wait_monitor(self):
42 for monitor in self.monitors:
43 monitor.wait_monitor()
46 first_outage = time.time()
49 for monitor in self.monitors:
50 monitor_result = monitor.get_result()
51 monitor_first_outage = monitor_result.get('first_outage', 0)
52 monitor_last_outage = monitor_result.get('last_outage', 0)
54 if monitor_first_outage == 0 or monitor_last_outage == 0:
57 if monitor_first_outage < first_outage:
58 first_outage = monitor_first_outage
60 if monitor_last_outage > last_outage:
61 last_outage = monitor_last_outage
63 last_outage - first_outage if last_outage > first_outage else 0
65 LOG.debug("outage_time is: %f", outage_time)
68 if "max_outage_time" in self._config["sla"]:
69 max_outage_time = self._config["sla"]["max_outage_time"]
70 elif "max_recover_time" in self._config["sla"]:
71 max_outage_time = self._config["sla"]["max_recover_time"]
73 raise RuntimeError("monitor max_outage_time config is not found")
74 self._result = {"outage_time": outage_time}
76 if outage_time > max_outage_time:
77 LOG.error("SLA failure: %f > %f", outage_time, max_outage_time)