Commit 515d4c3e authored by xa's avatar xa

display configuration

parent d6f4d530
......@@ -35,8 +35,14 @@ def main():
refresh_time=args.refresh_time,
window_time=args.window_time,
loop=loop)
threshold = args.check_hits
monitor.register_check("#/total/hits_per_sec", HitsCheck(threshold, args.check_sustain))
monitor.register_check("#/total/hits_per_sec", HitsCheck(args.check_hits, args.check_sustain))
monitor.formatter.meta = [
("Refresh time", "%ss" % args.refresh_time),
("Window time", "%ss" % args.window_time),
("Check hits", args.check_hits),
("Check sustain", "%ss" % args.check_sustain)
]
monitor.formatter.source = args.filename
monitor.start()
fake and fake.start()
loop.run_forever()
......
......@@ -15,7 +15,9 @@ class ConsoleFormatter:
"""Console formatter.
"""
def __init__(self):
def __init__(self, meta=None, source=None):
self.meta = meta
self.source = source or "-"
curses.initscr()
curses.start_color()
curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK)
......@@ -39,9 +41,11 @@ class ConsoleFormatter:
return
i = 1
i = self.format_sections(state, i)
i = self.format_alerts(state, i + 2)
i = self.format_global(state, i + 2)
i = self.format_source(i)
i = self.format_sections(state, i + 1)
i = self.format_alerts(state, i + 1)
self.format_global(state, i + 1)
self.format_meta(i + 1)
except Exception as error:
print(error)
pass
......@@ -54,6 +58,11 @@ class ConsoleFormatter:
except Exception:
pass
def format_source(self, line):
self.screen.addstr(line, 2, "From", curses.A_BOLD)
self.screen.addstr(line, 7, "%s" % self.source, curses.A_DIM)
return line + 1
def format_sections(self, state, line):
template = "{:<25} {:>6} {:>7} {:>3} {:>3} {:>3} {:>3} {:>3}"
rows = []
......@@ -85,7 +94,7 @@ class ConsoleFormatter:
line += 1
self.screen.addstr(line, 2, sep)
self.screen.refresh()
return line
return line + 1
def format_alerts(self, state, line):
......@@ -105,19 +114,29 @@ class ConsoleFormatter:
previous = row.type
self.screen.addstr(line, 2, row.message, f)
self.screen.refresh()
return line
return line + 1
def format_global(self, state, line):
data = [
"last seconds: %s" % round(state.metrics["delta"], 3),
"bytes/s: %s" % sizeof_fmt(state.metrics["total"]["bytes_per_sec"]),
"hits/s: %s" % state.metrics["total"]["hits_per_sec"],
"clients: %s" % len(state.metrics["clients"]),
"sections: %s" % len(state.metrics["sections"]),
"Bytes/s: %s" % sizeof_fmt(state.metrics["total"]["bytes_per_sec"]),
"Hits/s: %s" % state.metrics["total"]["hits_per_sec"],
"Clients: %s" % len(state.metrics["clients"]),
"Sections: %s" % len(state.metrics["sections"]),
]
self.screen.addstr(line, 2, "Global stats", curses.A_BOLD)
for row in data:
line += 1
self.screen.addstr(line, 2, row)
self.screen.refresh()
return line
return line + 1
def format_meta(self, line):
data = self.meta
if isinstance(data, dict):
data = data.items()
if data:
self.screen.addstr(line, 30, "Meta", curses.A_BOLD)
for row in data:
line += 1
self.screen.addstr(line, 30, "%s: %s" % row, curses.A_DIM)
return line + 1
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment