Add AB screen widget

This commit is contained in:
Andrey Pohilko 2012-10-01 15:39:27 +04:00
parent 0cbcf3fb3b
commit 364a72ecd6
3 changed files with 44 additions and 7 deletions

View File

@ -4,6 +4,7 @@ from Tank.Plugins.Aggregator import AggregatorPlugin, AbstractReader
import os
import subprocess
import tempfile
from Tank.Plugins.ConsoleOnline import ConsoleOnlinePlugin, AbstractInfoWidget
# TODO: 3 add console screen widget with info and PB measured via stderr info parsing
class ApacheBenchmarkPlugin(AbstractPlugin):
@ -12,7 +13,6 @@ class ApacheBenchmarkPlugin(AbstractPlugin):
def __init__(self, core):
AbstractPlugin.__init__(self, core)
self.end = None
self.out_file = None
self.process = None
self.concurrency = None
@ -42,6 +42,17 @@ class ApacheBenchmarkPlugin(AbstractPlugin):
if aggregator:
aggregator.reader = ABReader(aggregator, self)
try:
console = self.core.get_plugin_of_type(ConsoleOnlinePlugin)
except Exception, ex:
self.log.debug("Console not found: %s", ex)
console = None
if console:
widget = ABInfoWidget(self)
console.add_info_widget(widget)
def start_test(self):
args = ['ab', '-r', '-g', self.out_file,
'-n', self.requests,
@ -128,3 +139,28 @@ class ABReader(AbstractReader):
return None
class ABInfoWidget(AbstractInfoWidget):
def __init__(self, ab):
AbstractInfoWidget.__init__(self)
self.ab = ab
self.active_threads = 0
def get_index(self):
return 0
def aggregate_second(self, second_aggregate_data):
self.active_threads = second_aggregate_data.overall.active_threads
def render(self, screen):
ab_text = " Apache Benchmark Test "
space = screen.right_panel_width - len(ab_text) - 1
left_spaces = space / 2
right_spaces = space / 2
template = screen.markup.BG_BROWN + '~' * left_spaces + ab_text + ' ' + '~' * right_spaces + screen.markup.RESET + "\n"
template += " URL: %s\n"
template += " Concurrency: %s\n"
template += "Total Requests: %s"
data = (self.ab.url, self.ab.concurrency, self.ab.requests)
return template % data

View File

@ -123,9 +123,9 @@ class Screen(object):
widget_output = []
for index, widget in sorted(self.info_widgets.iteritems(), key=lambda(k, v): (v.get_index(), k)):
self.log.debug("Rendering info widget #%s: %s", index, widget)
widget_out = widget.render(self)
widget_output += widget_out.split("\n")
widget_out = widget.render(self).strip()
if widget_out:
widget_output += widget_out.split("\n")
widget_output += [""]
left_lines = self.__render_left_panel()

View File

@ -10,8 +10,6 @@ from Tank.Plugins.ConsoleOnline import ConsoleOnlinePlugin, AbstractInfoWidget
import time
# TODO: 3 add screen widget with info
# FIXME: 1 problem with small data count reading
class JMeterPlugin(AbstractPlugin):
SECTION = 'jmeter'
@ -205,12 +203,14 @@ class JMeterInfoWidget(AbstractInfoWidget, AggregateResultListener):
AbstractInfoWidget.__init__(self)
self.jmeter = jmeter
self.active_threads = 0
self.rps = 0
def get_index(self):
return 0
def aggregate_second(self, second_aggregate_data):
self.active_threads = second_aggregate_data.overall.active_threads
self.rps=second_aggregate_data.overall.RPS
def render(self, screen):
jmeter = " JMeter Test "
@ -219,7 +219,8 @@ class JMeterInfoWidget(AbstractInfoWidget, AggregateResultListener):
right_spaces = space / 2
template = screen.markup.BG_MAGENTA + '~' * left_spaces + jmeter + ' ' + '~' * right_spaces + screen.markup.RESET + "\n"
template += " Test Plan: %s\n"
template += "Active Threads: %s"
data = (os.path.basename(self.jmeter.original_jmx), self.active_threads)
template += "Active Threads: %s\n"
template += " Responses/s: %s"
data = (os.path.basename(self.jmeter.original_jmx), self.active_threads, self.rps)
return template % data