def get_widget(self): """ Add progress widget to console screen sidebar :rtype: SidebarWidget """ if not self.widget: if self.locustfile is not None: label = "Script: %s" % os.path.basename(self.locustfile) else: label = None self.widget = SidebarWidget(self, label) return self.widget
def get_widget(self): if not self.widget: if self.get_load().hold: label = "Siege Benchmark" else: label = None self.widget = SidebarWidget(self, label) return self.widget
def get_widget(self): if not self.widget: if self.script is not None: label = "Script: %s" % os.path.basename(self.script) else: label = None self.widget = SidebarWidget(self, label) return self.widget
def get_widget(self): """ Add progress widget to console screen sidebar :return: """ if not self.widget: proto = "https" if self.pbench.use_ssl else 'http' label = "Target: %s://%s:%s" % (proto, self.pbench.hostname, self.pbench.port) self.widget = SidebarWidget(self, label) return self.widget
class LocustIOExecutor(ScenarioExecutor, WidgetProvider, FileLister): def __init__(self): super(LocustIOExecutor, self).__init__() self.locustfile = None self.kpi_jtl = None self.process = None self.__out = None self.widget = None self.start_time = None self.is_master = False self.slaves_ldjson = None self.expected_slaves = 0 self.reader = None def prepare(self): self.__check_installed() self.locustfile = self.get_locust_file() if not self.locustfile or not os.path.exists(self.locustfile): raise ValueError("Locust file not found: %s" % self.locustfile) self.is_master = self.execution.get("master", self.is_master) if self.is_master: slaves = self.execution.get("slaves", ValueError("Slaves count required when starting in master mode")) self.expected_slaves = int(slaves) self.engine.existing_artifact(self.locustfile) if self.is_master: self.slaves_ldjson = self.engine.create_artifact("locust-slaves", ".ldjson") self.reader = SlavesReader(self.slaves_ldjson, self.expected_slaves, self.log) else: self.kpi_jtl = self.engine.create_artifact("kpi", ".jtl") self.reader = JTLReader(self.kpi_jtl, self.log, None) if isinstance(self.engine.aggregator, ConsolidatingAggregator): self.engine.aggregator.add_underling(self.reader) def __check_installed(self): tool = LocustIO(self.log) if not tool.check_if_installed(): if PY3: raise RuntimeError("LocustIO is not currently compatible with Python 3.x") raise RuntimeError("Unable to locate locustio package. Please install it like this: pip install locustio") def startup(self): self.start_time = time.time() load = self.get_load() hatch = load.concurrency / load.ramp_up if load.ramp_up else load.concurrency wrapper = os.path.join(os.path.abspath(os.path.dirname(__file__)), os.pardir, "resources", "locustio-taurus-wrapper.py") env = BetterDict() env.merge({"PYTHONPATH": self.engine.artifacts_dir + os.pathsep + os.getcwd()}) if os.getenv("PYTHONPATH"): env['PYTHONPATH'] = os.getenv("PYTHONPATH") + os.pathsep + env['PYTHONPATH'] args = [sys.executable, os.path.realpath(wrapper), '-f', os.path.realpath(self.locustfile)] args += ['--logfile=%s' % self.engine.create_artifact("locust", ".log")] args += ["--no-web", "--only-summary", ] args += ["--clients=%d" % load.concurrency, "--hatch-rate=%d" % math.ceil(hatch), ] if load.iterations: args.append("--num-request=%d" % load.iterations) if self.is_master: args.extend(["--master", '--expect-slaves=%s' % self.expected_slaves]) env["SLAVES_LDJSON"] = self.slaves_ldjson else: env["JTL"] = self.kpi_jtl host = self.get_scenario().get("default-address", None) if host: args.append("--host=%s" % host) self.__out = open(self.engine.create_artifact("locust", ".out"), 'w') self.process = self.execute(args, stderr=STDOUT, stdout=self.__out, env=env) def get_widget(self): """ Add progress widget to console screen sidebar :rtype: SidebarWidget """ if not self.widget: if self.locustfile is not None: label = "Script: %s" % os.path.basename(self.locustfile) else: label = None self.widget = SidebarWidget(self, label) return self.widget def check(self): # TODO: when we're in master mode and get no results and exceeded duration - shut down then if self.widget: self.widget.update() retcode = self.process.poll() if retcode is not None: self.log.info("Locust exit code: %s", retcode) if retcode != 0: raise RuntimeError("Locust exited with non-zero code: %s" % retcode) return True return False def resource_files(self): if not self.locustfile: self.locustfile = self.get_locust_file() return [self.locustfile] def get_locust_file(self): scenario = self.get_scenario() locustfile = scenario.get(Scenario.SCRIPT, ValueError("Please specify locusfile in 'script' option")) locustfile = self.engine.find_file(locustfile) return locustfile def shutdown(self): try: shutdown_process(self.process, self.log) finally: if self.__out: self.__out.close() def post_process(self): no_master_results = (self.is_master and not self.reader.cumulative) no_local_results = (not self.is_master and self.reader and not self.reader.buffer) if no_master_results or no_local_results: raise RuntimeWarning("Empty results, most likely Locust failed")
class LocustIOExecutor(ScenarioExecutor, WidgetProvider, FileLister): def __init__(self): super(LocustIOExecutor, self).__init__() self.locustfile = None self.kpi_jtl = None self.process = None self.__out = None self.widget = None self.start_time = None self.is_master = False self.slaves_ldjson = None self.expected_slaves = 0 self.reader = None def prepare(self): self.__check_installed() self.locustfile = self.get_locust_file() if not self.locustfile or not os.path.exists(self.locustfile): raise ValueError("Locust file not found: %s" % self.locustfile) self.is_master = self.execution.get("master", self.is_master) if self.is_master: slaves = self.execution.get( "slaves", ValueError( "Slaves count required when starting in master mode")) self.expected_slaves = int(slaves) self.engine.existing_artifact(self.locustfile) if self.is_master: self.slaves_ldjson = self.engine.create_artifact( "locust-slaves", ".ldjson") self.reader = SlavesReader(self.slaves_ldjson, self.expected_slaves, self.log) else: self.kpi_jtl = self.engine.create_artifact("kpi", ".jtl") self.reader = JTLReader(self.kpi_jtl, self.log, None) if isinstance(self.engine.aggregator, ConsolidatingAggregator): self.engine.aggregator.add_underling(self.reader) def __check_installed(self): tool = LocustIO(self.log) if not tool.check_if_installed(): if PY3: raise RuntimeError( "LocustIO is not currently compatible with Python 3.x") raise RuntimeError( "Unable to locate locustio package. Please install it like this: pip install locustio" ) def startup(self): self.start_time = time.time() load = self.get_load() hatch = load.concurrency / load.ramp_up if load.ramp_up else load.concurrency wrapper = os.path.join(os.path.abspath(os.path.dirname(__file__)), os.pardir, "resources", "locustio-taurus-wrapper.py") env = BetterDict() env.merge({ "PYTHONPATH": self.engine.artifacts_dir + os.pathsep + os.getcwd() }) if os.getenv("PYTHONPATH"): env['PYTHONPATH'] = os.getenv( "PYTHONPATH") + os.pathsep + env['PYTHONPATH'] args = [ sys.executable, os.path.realpath(wrapper), '-f', os.path.realpath(self.locustfile) ] args += [ '--logfile=%s' % self.engine.create_artifact("locust", ".log") ] args += [ "--no-web", "--only-summary", ] args += [ "--clients=%d" % load.concurrency, "--hatch-rate=%d" % math.ceil(hatch), ] if load.iterations: args.append("--num-request=%d" % load.iterations) if self.is_master: args.extend( ["--master", '--expect-slaves=%s' % self.expected_slaves]) env["SLAVES_LDJSON"] = self.slaves_ldjson else: env["JTL"] = self.kpi_jtl host = self.get_scenario().get("default-address", None) if host: args.append("--host=%s" % host) self.__out = open(self.engine.create_artifact("locust", ".out"), 'w') self.process = self.execute(args, stderr=STDOUT, stdout=self.__out, env=env) def get_widget(self): """ Add progress widget to console screen sidebar :rtype: SidebarWidget """ if not self.widget: if self.locustfile is not None: label = "Script: %s" % os.path.basename(self.locustfile) else: label = None self.widget = SidebarWidget(self, label) return self.widget def check(self): # TODO: when we're in master mode and get no results and exceeded duration - shut down then if self.widget: self.widget.update() retcode = self.process.poll() if retcode is not None: self.log.info("Locust exit code: %s", retcode) if retcode != 0: raise RuntimeError("Locust exited with non-zero code: %s" % retcode) return True return False def resource_files(self): if not self.locustfile: self.locustfile = self.get_locust_file() return [self.locustfile] def get_locust_file(self): scenario = self.get_scenario() locustfile = scenario.get( Scenario.SCRIPT, ValueError("Please specify locusfile in 'script' option")) locustfile = self.engine.find_file(locustfile) return locustfile def shutdown(self): try: shutdown_process(self.process, self.log) finally: if self.__out: self.__out.close() def post_process(self): no_master_results = (self.is_master and not self.reader.cumulative) no_local_results = (not self.is_master and self.reader and not self.reader.buffer) if no_master_results or no_local_results: raise RuntimeWarning("Empty results, most likely Locust failed")
def get_widget(self): if not self.widget: self.widget = SidebarWidget(self, self.tsung_controller_id) return self.widget