<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[15373] CalendarServer/trunk/calendarserver/tools/dashboard.py</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/15373">15373</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2015-12-09 09:49:04 -0800 (Wed, 09 Dec 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Support viewing multiple servers (one at a time). Code refactor to simplify each panel.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunkcalendarservertoolsdashboardpy">CalendarServer/trunk/calendarserver/tools/dashboard.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunkcalendarservertoolsdashboardpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/tools/dashboard.py (15372 => 15373)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/calendarserver/tools/dashboard.py        2015-12-08 21:44:13 UTC (rev 15372)
+++ CalendarServer/trunk/calendarserver/tools/dashboard.py        2015-12-09 17:49:04 UTC (rev 15373)
</span><span class="lines">@@ -20,12 +20,12 @@
</span><span class="cx"> &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx"> import argparse
</span><ins>+import collections
</ins><span class="cx"> import curses.panel
</span><span class="cx"> import errno
</span><span class="cx"> import fcntl
</span><span class="cx"> import json
</span><span class="cx"> import logging
</span><del>-import os
</del><span class="cx"> import sched
</span><span class="cx"> import socket
</span><span class="cx"> import struct
</span><span class="lines">@@ -34,60 +34,42 @@
</span><span class="cx"> import time
</span><span class="cx"> 
</span><span class="cx"> LOG_FILENAME = 'db.log'
</span><del>-# logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG)
</del><ins>+#logging.basicConfig(filename=LOG_FILENAME, level=logging.DEBUG)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-def usage(e=None):
-    name = os.path.basename(sys.argv[0])
-    print(&quot;usage: %s [options]&quot; % (name,))
-    print(&quot;&quot;)
-    print(&quot;  TODO: describe usage&quot;)
-    print(&quot;&quot;)
-    print(&quot;options:&quot;)
-    print(&quot;  -h --help: print this help and exit&quot;)
-    print(&quot;  -t: text output, not curses&quot;)
-    print(&quot;  -s: server host (and optional port) [localhost:8100]&quot;)
-    print(&quot;      or unix socket path prefixed by 'unix:'&quot;)
-    print(&quot;&quot;)
-
-    if e:
-        sys.exit(64)
-    else:
-        sys.exit(0)
-
-
-
</del><span class="cx"> def main():
</span><span class="cx">     parser = argparse.ArgumentParser(description=&quot;Dashboard service for CalendarServer.&quot;)
</span><span class="cx">     parser.add_argument(&quot;-t&quot;, action=&quot;store_false&quot;, help=&quot;text output, not curses&quot;)
</span><del>-    parser.add_argument(&quot;-s&quot;, default=&quot;localhost:8100&quot;, help=&quot;server host (and optional port), or unix socket path prefixed by 'unix:'&quot;)
</del><ins>+    parser.add_argument(&quot;-s&quot;, nargs=&quot;*&quot;, default=[&quot;localhost:8100&quot;], help=&quot;server host (and optional port), or unix socket path prefixed by 'unix:'&quot;)
</ins><span class="cx">     args = parser.parse_args()
</span><span class="cx"> 
</span><span class="cx">     #
</span><span class="cx">     # Get configuration
</span><span class="cx">     #
</span><span class="cx">     useCurses = args.t
</span><del>-    if not args.s.startswith(&quot;unix:&quot;):
-        server = args.s.split(&quot;:&quot;)
-        if len(server) == 1:
-            server.append(8100)
</del><ins>+    servers = []
+    for server in args.s:
+        if not server.startswith(&quot;unix:&quot;):
+            server = server.split(&quot;:&quot;)
+            if len(server) == 1:
+                server.append(8100)
+            else:
+                server[1] = int(server[1])
+            servers.append(tuple(server))
</ins><span class="cx">         else:
</span><del>-            server[1] = int(server[1])
-        server = tuple(server)
-    else:
-        server = args.s
</del><ins>+            servers.append(server)
</ins><span class="cx"> 
</span><span class="cx">     if useCurses:
</span><span class="cx">         def _wrapped(stdscrn):
</span><span class="cx">             curses.curs_set(0)
</span><span class="cx">             curses.use_default_colors()
</span><span class="cx">             curses.init_pair(1, curses.COLOR_RED, curses.COLOR_WHITE)
</span><del>-            d = Dashboard(server, stdscrn, True)
</del><ins>+            d = Dashboard(servers, stdscrn, True)
</ins><span class="cx">             d.run()
</span><span class="cx">         curses.wrapper(_wrapped)
</span><span class="cx">     else:
</span><del>-        d = Dashboard(server, None, False)
</del><ins>+        d = Dashboard(servers, None, False)
</ins><span class="cx">         d.run()
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -121,20 +103,24 @@
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">     screen = None
</span><del>-    registered_windows = {}
</del><ins>+    registered_windows = collections.OrderedDict()
</ins><span class="cx">     registered_window_sets = {
</span><span class="cx">         &quot;H&quot;: (&quot;HTTP Panels&quot;, [],),
</span><span class="cx">         &quot;J&quot;: (&quot;Jobs Panels&quot;, [],),
</span><span class="cx">     }
</span><del>-    registered_order = []
</del><span class="cx"> 
</span><del>-    def __init__(self, server, screen, usesCurses):
</del><ins>+    def __init__(self, servers, screen, usesCurses):
</ins><span class="cx">         self.screen = screen
</span><span class="cx">         self.usesCurses = usesCurses
</span><span class="cx">         self.paused = False
</span><span class="cx">         self.seconds = 0.1 if usesCurses else 1.0
</span><span class="cx">         self.sched = sched.scheduler(time.time, time.sleep)
</span><del>-        self.client = DashboardClient(server)
</del><ins>+
+        self.servers = servers
+        self.current_server = 0
+        self.server_window = None
+
+        self.client = DashboardClient(servers[0])
</ins><span class="cx">         self.client_error = False
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -147,7 +133,6 @@
</span><span class="cx">         available window type.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         cls.registered_windows[keypress] = wtype
</span><del>-        cls.registered_order.append(keypress)
</del><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classmethod
</span><span class="lines">@@ -179,7 +164,7 @@
</span><span class="cx">         # Toggle a specific window on or off
</span><span class="cx">         if isinstance(wtype, type):
</span><span class="cx">             if wtype not in [type(w) for w in self.windows]:
</span><del>-                self.windows.append(wtype(self.usesCurses, self.client).makeWindow())
</del><ins>+                self.windows.append(wtype(self.usesCurses, self).makeWindow())
</ins><span class="cx">                 self.windows[-1].activate()
</span><span class="cx">             else:
</span><span class="cx">                 for window in self.windows:
</span><span class="lines">@@ -198,25 +183,33 @@
</span><span class="cx">                     window.deactivate()
</span><span class="cx">                 self.windows = []
</span><span class="cx">             top = 0
</span><ins>+
+            if len(self.servers) &gt; 1:
+                self.server_window = ServersMenu(self.usesCurses, self).makeWindow()
+                self.windows.append(self.server_window)
+                self.windows[-1].activate()
+                top += self.windows[-1].nlines + 1
+            help_top = top
+
</ins><span class="cx">             if wtype is None:
</span><span class="cx">                 # All windows in registered order
</span><del>-                ordered_windows = [self.registered_windows[i] for i in self.registered_order]
</del><ins>+                ordered_windows = self.registered_windows.values()
</ins><span class="cx">             else:
</span><span class="cx">                 ordered_windows = list(wtype)
</span><span class="cx">             for wtype in filter(lambda x: x.all, ordered_windows):
</span><del>-                new_win = wtype(self.usesCurses, self.client).makeWindow(top=top)
</del><ins>+                new_win = wtype(self.usesCurses, self).makeWindow(top=top)
</ins><span class="cx">                 logging.debug('created %r at panel level %r' % (new_win, new_win.z_order))
</span><del>-                self.windows.append(wtype(self.usesCurses, self.client).makeWindow(top=top))
</del><ins>+                self.windows.append(wtype(self.usesCurses, self).makeWindow(top=top))
</ins><span class="cx">                 self.windows[-1].activate()
</span><span class="cx">                 top += self.windows[-1].nlines + 1
</span><span class="cx"> 
</span><span class="cx">             # Don't display help panel if the window is too narrow
</span><span class="cx">             if self.usesCurses:
</span><span class="cx">                 term_w, term_h = terminal_size()
</span><del>-                logging.debug(&quot;logger displayWindow: rows: %s  cols: %s&quot; % (term_h, term_w))
</del><ins>+                logging.debug(&quot;HelpWindow: rows: %s  cols: %s&quot; % (term_h, term_w))
</ins><span class="cx">                 if int(term_w) &gt; 100:
</span><del>-                    logging.debug('term_w &gt; 100, making window with top at %d' % (top))
-                    self.windows.append(HelpWindow(self.usesCurses, self.client).makeWindow(top=top))
</del><ins>+                    logging.debug('HelpWindow: term_w &gt; 100, making window with top at %d' % (top))
+                    self.windows.append(HelpWindow(self.usesCurses, self).makeWindow(top=help_top))
</ins><span class="cx">                     self.windows[-1].activate()
</span><span class="cx"> 
</span><span class="cx">         if self.usesCurses:
</span><span class="lines">@@ -237,7 +230,7 @@
</span><span class="cx">             top = 0
</span><span class="cx">             for old in old_windows:
</span><span class="cx">                 logging.debug('processing window of type %r' % (type(old)))
</span><del>-                self.windows.append(old.__class__(self.usesCurses, self.client).makeWindow(top=top))
</del><ins>+                self.windows.append(old.__class__(self.usesCurses, self).makeWindow(top=top))
</ins><span class="cx">                 self.windows[-1].activate()
</span><span class="cx">                 # Allow the help window to float on the right edge
</span><span class="cx">                 if old.__class__.__name__ != &quot;HelpWindow&quot;:
</span><span class="lines">@@ -271,34 +264,53 @@
</span><span class="cx"> 
</span><span class="cx">         # Check keystrokes
</span><span class="cx">         if self.usesCurses:
</span><del>-            try:
-                c = self.windows[-1].window.getkey()
-            except:
-                c = -1
-            if c == &quot;q&quot;:
-                sys.exit(0)
-            elif c == &quot; &quot;:
-                self.paused = not self.paused
-            elif c == &quot;t&quot;:
-                self.seconds = 1.0 if self.seconds == 0.1 else 0.1
-            elif c == &quot;a&quot;:
-                self.displayWindow(None)
-            elif c == &quot;n&quot;:
-                if self.windows:
-                    for window in self.windows:
-                        window.deactivate()
-                    self.windows = []
-                    self.displayWindow(self.registered_windows[&quot;h&quot;])
-            elif c in self.registered_windows:
-                self.displayWindow(self.registered_windows[c])
-            elif c in self.registered_window_sets:
-                self.displayWindow(self.registered_window_sets[c][1])
</del><ins>+            self.processKeys()
</ins><span class="cx"> 
</span><span class="cx">         if not initialUpdate:
</span><span class="cx">             self.sched.enter(self.seconds, 0, self.updateDisplay, ())
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    def processKeys(self):
+        &quot;&quot;&quot;
+        Check for a key press.
+        &quot;&quot;&quot;
+        try:
+            self.windows[-1].window.keypad(1)
+            c = self.windows[-1].window.getkey()
+        except:
+            c = -1
+        if c == &quot;q&quot;:
+            sys.exit(0)
+        elif c == &quot; &quot;:
+            self.paused = not self.paused
+        elif c == &quot;t&quot;:
+            self.seconds = 1.0 if self.seconds == 0.1 else 0.1
+        elif c == &quot;a&quot;:
+            self.displayWindow(None)
+        elif c == &quot;n&quot;:
+            if self.windows:
+                for window in self.windows:
+                    window.deactivate()
+                self.windows = []
+                self.displayWindow(self.registered_windows[&quot;h&quot;])
</ins><span class="cx"> 
</span><ins>+        elif c in self.registered_windows:
+            self.displayWindow(self.registered_windows[c])
+
+        elif c in self.registered_window_sets:
+            self.displayWindow(self.registered_window_sets[c][1])
+
+        elif c in (curses.keyname(curses.KEY_LEFT), curses.keyname(curses.KEY_RIGHT)) and self.server_window:
+            self.current_server += (-1 if c == curses.keyname(curses.KEY_LEFT) else 1)
+            if self.current_server &lt; 0:
+                self.current_server = 0
+            elif self.current_server &gt;= len(self.servers):
+                self.current_server = len(self.servers) - 1
+            self.client = DashboardClient(self.servers[self.current_server])
+            self.resetWindows()
+
+
+
</ins><span class="cx"> class DashboardClient(object):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Client that connects to a server and fetches information.
</span><span class="lines">@@ -378,10 +390,30 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         No need to monitor this item.
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        self.items.remove(item)
</del><ins>+        try:
+            self.items.remove(item)
+        except ValueError:
+            # Don't care if the item is not present
+            pass
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+class Point(object):
+
+    def __init__(self, x=0, y=0):
+        self.x = x
+        self.y = y
+
+
+    def xplus(self, xdiff=1):
+        self.x += xdiff
+
+
+    def yplus(self, ydiff=1):
+        self.y += ydiff
+
+
+
</ins><span class="cx"> class BaseWindow(object):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Common behavior for window types.
</span><span class="lines">@@ -395,9 +427,9 @@
</span><span class="cx">     formatWidth = 0
</span><span class="cx">     additionalRows = 0
</span><span class="cx"> 
</span><del>-    def __init__(self, usesCurses, client):
</del><ins>+    def __init__(self, usesCurses, dashboard):
</ins><span class="cx">         self.usesCurses = usesCurses
</span><del>-        self.client = client
</del><ins>+        self.dashboard = dashboard
</ins><span class="cx">         self.rowCount = 0
</span><span class="cx">         self.needsReset = False
</span><span class="cx">         self.z_order = 'bottom'
</span><span class="lines">@@ -453,7 +485,7 @@
</span><span class="cx">     def requiresReset(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Indicates that the window needs a full reset, because e.g., the
</span><del>-        number of items it didplays has changed.
</del><ins>+        number of items it displays has changed.
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         return self.needsReset
</span><span class="cx"> 
</span><span class="lines">@@ -463,15 +495,20 @@
</span><span class="cx">         About to start displaying.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         if self.clientItem:
</span><del>-            self.client.addItem(self.clientItem)
</del><ins>+            self.dashboard.client.addItem(self.clientItem)
</ins><span class="cx"> 
</span><ins>+        # Update once when activated
+        if not self.requiresUpdate():
+            self.update()
</ins><span class="cx"> 
</span><ins>+
</ins><span class="cx">     def deactivate(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Clear any drawing done by the current window type.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         if self.clientItem:
</span><del>-            self.client.removeItem(self.clientItem)
</del><ins>+            self.dashboard.client.removeItem(self.clientItem)
+
</ins><span class="cx">         if self.usesCurses:
</span><span class="cx">             self.window.erase()
</span><span class="cx">             self.window.refresh()
</span><span class="lines">@@ -484,411 +521,199 @@
</span><span class="cx">         raise NotImplementedError()
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def clientData(self):
-        return self.client.currentData.get(self.clientItem)
-
-
-    def readItem(self, item):
-        return self.client.getOneItem(item)
-
-
-
-class HelpWindow(BaseWindow):
-    &quot;&quot;&quot;
-    Display help for the dashboard.
-    &quot;&quot;&quot;
-
-    help = &quot;dashboard help&quot;
-    all = False
-    helpItems = (
-        &quot;a - all windows&quot;,
-        &quot;n - no windows&quot;,
-        &quot;  - (space) pause dashboard polling&quot;,
-        &quot;t - toggle update between 0.1 and 1.0 seconds&quot;,
-        &quot;&quot;,
-        &quot;q - exit the dashboard&quot;,
-    )
-
-    windowTitle = &quot;Help&quot;
-    formatWidth = 48
-    additionalRows = 3
-
-    def makeWindow(self, top=0, left=0):
-        term_w, _ignore_term_h = terminal_size()
-        help_x_offset = term_w - self.formatWidth
-        return super(HelpWindow, self).makeWindow(0, help_x_offset)
-
-
-    def updateRowCount(self):
-        self.rowCount = len(self.helpItems) + len(filter(lambda x: len(x[1]) != 0, Dashboard.registered_window_sets.values())) + len(Dashboard.registered_windows)
-
-
-    def requiresUpdate(self):
-        return False
-
-
-    def update(self):
-
</del><ins>+    def tableHeader(self, hdrs, count):
+        &quot;&quot;&quot;
+        Generate the header rows.
+        &quot;&quot;&quot;
</ins><span class="cx">         if self.usesCurses:
</span><span class="cx">             self.window.erase()
</span><span class="cx">             self.window.border()
</span><del>-            self.window.addstr(0, 2, &quot;Hotkeys&quot;)
</del><ins>+            self.window.addstr(
+                0, 2,
+                self.title + &quot; {} ({})&quot;.format(count, self.iter)
+            )
</ins><span class="cx"> 
</span><del>-        x = 1
-        y = 1
</del><ins>+        pt = Point(1, 1)
</ins><span class="cx"> 
</span><span class="cx">         if not self.usesCurses:
</span><span class="cx">             print(&quot;------------ {}&quot;.format(self.title))
</span><span class="cx"> 
</span><del>-        items = []
-        for keypress, wtype in sorted(
-            Dashboard.registered_windows.items(), key=lambda x: x[0]
-        ):
-            items.append(&quot;{} - {}&quot;.format(keypress, wtype.help))
-
-        items.append(&quot;&quot;)
-        for key, value in Dashboard.registered_window_sets.items():
-            description, panels = value
-            if panels:
-                items.append(&quot;{} - {}&quot;.format(key, description))
-
-        items.extend(self.helpItems)
-        for item in items:
</del><ins>+        for hdr in hdrs:
</ins><span class="cx">             if self.usesCurses:
</span><del>-                self.window.addstr(y, x, item)
</del><ins>+                self.window.addstr(pt.y, pt.x, hdr, curses.A_REVERSE)
</ins><span class="cx">             else:
</span><del>-                print(item)
-            y += 1
</del><ins>+                print(hdr)
+            pt.yplus()
</ins><span class="cx"> 
</span><del>-        if not self.usesCurses:
-            print(&quot;&quot;)
</del><ins>+        return pt
</ins><span class="cx"> 
</span><ins>+
+    def tableFooter(self, feet, pt):
+        &quot;&quot;&quot;
+        Generate the footer rows.
+        &quot;&quot;&quot;
</ins><span class="cx">         if self.usesCurses:
</span><del>-            self.window.refresh()
</del><ins>+            self.window.hline(pt.y, pt.x, &quot;-&quot;, self.formatWidth - 2)
+            pt.yplus()
+            for footer in feet:
+                self.window.addstr(pt.y, pt.x, footer)
+                pt.yplus()
+        else:
+            for footer in feet:
+                print(footer)
+                pt.yplus()
+            print(&quot;&quot;)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    def tableRow(self, text, pt, style=curses.A_NORMAL):
+        &quot;&quot;&quot;
+        Generate a single row.
+        &quot;&quot;&quot;
+        try:
+            if self.usesCurses:
+                self.window.addstr(
+                    pt.y, pt.x, text,
+                    style
+                )
+            else:
+                print(text)
+        except curses.error:
+            pass
+        pt.yplus()
</ins><span class="cx"> 
</span><del>-class JobsWindow(BaseWindow):
-    &quot;&quot;&quot;
-    Display the status of the server's job queue.
-    &quot;&quot;&quot;
</del><span class="cx"> 
</span><del>-    help = &quot;server jobs&quot;
-    clientItem = &quot;jobs&quot;
</del><ins>+    def clientData(self):
+        return self.dashboard.client.currentData.get(self.clientItem)
</ins><span class="cx"> 
</span><del>-    windowTitle = &quot;Jobs&quot;
-    formatWidth = 98
-    additionalRows = 6
</del><span class="cx"> 
</span><del>-    def updateRowCount(self):
-        self.rowCount = defaultIfNone(self.readItem(&quot;jobcount&quot;), 0)
</del><ins>+    def readItem(self, item):
+        return self.dashboard.client.getOneItem(item)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def update(self):
-        records = defaultIfNone(self.clientData(), {})
-        if len(records) != self.rowCount:
-            self.needsReset = True
-            return
-        self.iter += 1
</del><span class="cx"> 
</span><del>-        if self.usesCurses:
-            self.window.erase()
-            self.window.border()
-            self.window.addstr(
-                0, 2,
-                self.title + &quot; {} ({})&quot;.format(len(records), self.iter)
-            )
</del><ins>+class ServersMenu(BaseWindow):
+    &quot;&quot;&quot;
+    Top menu if multiple servers are present.
+    &quot;&quot;&quot;
</ins><span class="cx"> 
</span><del>-        x = 1
-        y = 1
-        s1 = &quot; {:&lt;40}{:&gt;8}{:&gt;10}{:&gt;8}{:&gt;8}{:&gt;10}{:&gt;10} &quot;.format(
-            &quot;Work Type&quot;, &quot;Queued&quot;, &quot;Assigned&quot;, &quot;Late&quot;, &quot;Failed&quot;, &quot;Completed&quot;, &quot;Av-Time&quot;,
-        )
-        s2 = &quot; {:&lt;40}{:&gt;8}{:&gt;10}{:&gt;8}{:&gt;8}{:&gt;10}{:&gt;10} &quot;.format(
-            &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;(ms)&quot;,
-        )
-        if self.usesCurses:
-            self.window.addstr(y, x, s1, curses.A_REVERSE)
-            self.window.addstr(y + 1, x, s2, curses.A_REVERSE)
-        else:
-            print(&quot;------------ {}&quot;.format(self.title))
-            print(s1)
-            print(s2)
-        y += 2
-        total_queued = 0
-        total_assigned = 0
-        total_late = 0
-        total_failed = 0
-        total_completed = 0
-        total_time = 0.0
-        for work_type, details in sorted(records.items(), key=lambda x: x[0]):
-            total_queued += details[&quot;queued&quot;]
-            total_assigned += details[&quot;assigned&quot;]
-            total_late += details[&quot;late&quot;]
-            total_failed += details[&quot;failed&quot;]
-            total_completed += details[&quot;completed&quot;]
-            total_time += details[&quot;time&quot;]
-            changed = (
-                work_type in self.lastResult and
-                self.lastResult[work_type][&quot;queued&quot;] != details[&quot;queued&quot;]
-            )
-            s = &quot;{}{:&lt;40}{:&gt;8}{:&gt;10}{:&gt;8}{:&gt;8}{:&gt;10}{:&gt;10.1f} &quot;.format(
-                &quot;&gt;&quot; if details[&quot;queued&quot;] else &quot; &quot;,
-                work_type,
-                details[&quot;queued&quot;],
-                details[&quot;assigned&quot;],
-                details[&quot;late&quot;],
-                details[&quot;failed&quot;],
-                details[&quot;completed&quot;],
-                safeDivision(details[&quot;time&quot;], details[&quot;completed&quot;], 1000.0)
-            )
-            try:
-                if self.usesCurses:
-                    self.window.addstr(
-                        y, x, s,
-                        curses.A_REVERSE if changed else (
-                            curses.A_BOLD if details[&quot;queued&quot;] else curses.A_NORMAL
-                        )
-                    )
-                else:
-                    print(s)
-            except curses.error:
-                pass
-            y += 1
</del><ins>+    help = &quot;servers help&quot;
+    all = False
</ins><span class="cx"> 
</span><del>-        s = &quot; {:&lt;40}{:&gt;8}{:&gt;10}{:&gt;8}{:&gt;8}{:&gt;10}{:&gt;10.1f} &quot;.format(
-            &quot;Total:&quot;,
-            total_queued,
-            total_assigned,
-            total_late,
-            total_failed,
-            total_completed,
-            safeDivision(total_time, total_completed, 1000.0)
-        )
-        if self.usesCurses:
-            self.window.hline(y, x, &quot;-&quot;, self.formatWidth - 2)
-            y += 1
-            self.window.addstr(y, x, s)
-        else:
-            print(s)
-            print(&quot;&quot;)
-        y += 1
</del><ins>+    windowTitle = &quot;Servers&quot;
+    formatWidth = 0
+    additionalRows = 0
</ins><span class="cx"> 
</span><del>-        if self.usesCurses:
-            self.window.refresh()
</del><ins>+    def makeWindow(self, top=0, left=0):
+        term_w, _ignore_term_h = terminal_size()
+        self.formatWidth = term_w - 50
+        return super(ServersMenu, self).makeWindow(0, 0)
</ins><span class="cx"> 
</span><del>-        self.lastResult = records
</del><span class="cx"> 
</span><ins>+    def updateRowCount(self):
+        self.rowCount = 1
</ins><span class="cx"> 
</span><span class="cx"> 
</span><del>-class AssignmentsWindow(BaseWindow):
-    &quot;&quot;&quot;
-    Displays the status of the server's master process worker slave slots.
-    &quot;&quot;&quot;
</del><ins>+    def requiresUpdate(self):
+        return False
</ins><span class="cx"> 
</span><del>-    help = &quot;server child job assignments&quot;
-    clientItem = &quot;job_assignments&quot;
</del><span class="cx"> 
</span><del>-    windowTitle = &quot;Job Assignments&quot;
-    formatWidth = 40
-    additionalRows = 5
</del><ins>+    def update(self):
</ins><span class="cx"> 
</span><del>-    def updateRowCount(self):
-        self.rowCount = len(defaultIfNone(self.readItem(self.clientItem), {&quot;workers&quot;: ()})[&quot;workers&quot;])
</del><ins>+        if not self.usesCurses:
+            return
</ins><span class="cx"> 
</span><ins>+        self.window.erase()
</ins><span class="cx"> 
</span><del>-    def update(self):
-        data = defaultIfNone(self.clientData(), {&quot;workers&quot;: {}, &quot;level&quot;: 0})
-        records = data[&quot;workers&quot;]
-        if len(records) != self.rowCount:
-            self.needsReset = True
-            return
-        self.iter += 1
</del><ins>+        pt = Point()
+        s = &quot;Servers: |&quot;
+        self.window.addstr(pt.y, pt.x, s)
+        pt.xplus(len(s))
</ins><span class="cx"> 
</span><del>-        if self.usesCurses:
-            self.window.erase()
-            self.window.border()
</del><ins>+        selected_server = None
+        for ctr, server in enumerate(self.dashboard.servers):
+            s = &quot; {:02d} &quot;.format(ctr + 1)
</ins><span class="cx">             self.window.addstr(
</span><del>-                0, 2,
-                self.title + &quot; {} ({})&quot;.format(len(records), self.iter)
</del><ins>+                pt.y, pt.x, s,
+                curses.A_REVERSE if ctr == self.dashboard.current_server else curses.A_NORMAL
</ins><span class="cx">             )
</span><ins>+            pt.xplus(len(s))
+            self.window.addstr(pt.y, pt.x, &quot;|&quot;)
+            pt.xplus()
+            if ctr == self.dashboard.current_server:
+                selected_server = &quot;{}:{}&quot;.format(*server)
</ins><span class="cx"> 
</span><del>-        x = 1
-        y = 1
-        s = &quot; {:&gt;4}{:&gt;12}{:&gt;8}{:&gt;12} &quot;.format(
-            &quot;Slot&quot;, &quot;assigned&quot;, &quot;load&quot;, &quot;completed&quot;
-        )
-        if self.usesCurses:
-            self.window.addstr(y, x, s, curses.A_REVERSE)
-        else:
-            print(&quot;------------ {}&quot;.format(self.title))
-            print(s)
-        y += 1
-        total_assigned = 0
-        total_completed = 0
-        for ctr, details in enumerate(records):
-            assigned, load, completed = details
-            total_assigned += assigned
-            total_completed += completed
-            changed = (
-                ctr in self.lastResult and
-                self.lastResult[ctr] != assigned
-            )
-            s = &quot; {:&gt;4}{:&gt;12}{:&gt;8}{:&gt;12} &quot;.format(
-                ctr,
-                assigned,
-                load,
-                completed,
-            )
-            try:
-                if self.usesCurses:
-                    self.window.addstr(
-                        y, x, s,
-                        curses.A_REVERSE if changed else curses.A_NORMAL
-                    )
-                else:
-                    print(s)
-            except curses.error:
-                pass
-            y += 1
</del><ins>+        self.window.addstr(pt.y, pt.x, &quot; {}&quot;.format(selected_server))
</ins><span class="cx"> 
</span><del>-        s = &quot; {:&lt;6}{:&gt;10}{:&gt;8}{:&gt;12}&quot;.format(
-            &quot;Total:&quot;,
-            total_assigned,
-            &quot;{}%&quot;.format(data[&quot;level&quot;]),
-            total_completed,
-        )
-        if self.usesCurses:
-            self.window.hline(y, x, &quot;-&quot;, self.formatWidth - 2)
-            y += 1
-            self.window.addstr(y, x, s)
-        else:
-            print(s)
-            print(&quot;&quot;)
-        y += 1
</del><ins>+        self.window.refresh()
</ins><span class="cx"> 
</span><del>-        if self.usesCurses:
-            self.window.refresh()
</del><span class="cx"> 
</span><del>-        self.lastResult = records
</del><span class="cx"> 
</span><del>-
-
-class HTTPSlotsWindow(BaseWindow):
</del><ins>+class HelpWindow(BaseWindow):
</ins><span class="cx">     &quot;&quot;&quot;
</span><del>-    Displays the status of the server's master process worker slave slots.
</del><ins>+    Display help for the dashboard.
</ins><span class="cx">     &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-    help = &quot;server child slots&quot;
-    clientItem = &quot;slots&quot;
</del><ins>+    help = &quot;Help&quot;
+    all = False
+    helpItems = (
+        &quot; a - All Panels&quot;,
+        &quot; n - No Panels&quot;,
+        &quot;&quot;,
+        &quot;   - (space) Pause&quot;,
+        &quot; t - Toggle Update Speed&quot;,
+        &quot;&quot;,
+        &quot; q - Quit&quot;,
+    )
</ins><span class="cx"> 
</span><del>-    windowTitle = &quot;HTTP Slots&quot;
-    formatWidth = 72
-    additionalRows = 5
</del><ins>+    windowTitle = &quot;Help&quot;
+    formatWidth = 28
+    additionalRows = 3
</ins><span class="cx"> 
</span><ins>+    def makeWindow(self, top=0, left=0):
+        term_w, _ignore_term_h = terminal_size()
+        help_x_offset = term_w - self.formatWidth
+        return super(HelpWindow, self).makeWindow(0, help_x_offset)
+
+
</ins><span class="cx">     def updateRowCount(self):
</span><del>-        self.rowCount = len(defaultIfNone(self.readItem(self.clientItem), {&quot;slots&quot;: ()})[&quot;slots&quot;])
</del><ins>+        self.rowCount = len(self.helpItems) + len(filter(lambda x: len(x[1]) != 0, Dashboard.registered_window_sets.values())) + len(Dashboard.registered_windows)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    def requiresUpdate(self):
+        return False
+
+
</ins><span class="cx">     def update(self):
</span><del>-        data = defaultIfNone(self.clientData(), {&quot;slots&quot;: {}, &quot;overloaded&quot;: False})
-        records = data[&quot;slots&quot;]
-        if len(records) != self.rowCount:
-            self.needsReset = True
-            return
-        self.iter += 1
</del><span class="cx"> 
</span><span class="cx">         if self.usesCurses:
</span><span class="cx">             self.window.erase()
</span><span class="cx">             self.window.border()
</span><del>-            self.window.addstr(
-                0, 2,
-                self.title + &quot; {} ({})&quot;.format(len(records), self.iter)
-            )
</del><ins>+            self.window.addstr(0, 2, &quot;Hotkeys&quot;)
</ins><span class="cx"> 
</span><del>-        x = 1
-        y = 1
-        s = &quot; {:&gt;4}{:&gt;8}{:&gt;8}{:&gt;8}{:&gt;8}{:&gt;8}{:&gt;8}{:&gt;8}{:&gt;8} &quot;.format(
-            &quot;Slot&quot;, &quot;unack&quot;, &quot;ack&quot;, &quot;uncls&quot;, &quot;total&quot;,
-            &quot;start&quot;, &quot;strting&quot;, &quot;stopped&quot;, &quot;abd&quot;
-        )
-        if self.usesCurses:
-            self.window.addstr(y, x, s, curses.A_REVERSE)
-        else:
</del><ins>+        pt = Point(1, 1)
+
+        if not self.usesCurses:
</ins><span class="cx">             print(&quot;------------ {}&quot;.format(self.title))
</span><del>-            print(s)
-        y += 1
-        for record in sorted(records, key=lambda x: x[&quot;slot&quot;]):
-            changed = (
-                record[&quot;slot&quot;] in self.lastResult and
-                self.lastResult[record[&quot;slot&quot;]] != record
-            )
-            s = &quot; {:&gt;4}{:&gt;8}{:&gt;8}{:&gt;8}{:&gt;8}{:&gt;8}{:&gt;8}{:&gt;8}{:&gt;8} &quot;.format(
-                record[&quot;slot&quot;],
-                record[&quot;unacknowledged&quot;],
-                record[&quot;acknowledged&quot;],
-                record[&quot;unclosed&quot;],
-                record[&quot;total&quot;],
-                record[&quot;started&quot;],
-                record[&quot;starting&quot;],
-                record[&quot;stopped&quot;],
-                record[&quot;abandoned&quot;],
-            )
-            try:
-                count = record[&quot;unacknowledged&quot;] + record[&quot;acknowledged&quot;]
-                if self.usesCurses:
-                    self.window.addstr(
-                        y, x, s,
-                        curses.A_REVERSE if changed else (
-                            curses.A_BOLD if count else curses.A_NORMAL
-                        )
-                    )
-                else:
-                    print(s)
-            except curses.error:
-                pass
-            y += 1
</del><span class="cx"> 
</span><del>-        s = &quot; {:&lt;12}{:&gt;8}{:&gt;16}&quot;.format(
-            &quot;Total:&quot;,
-            sum(
-                [
-                    record[&quot;unacknowledged&quot;] + record[&quot;acknowledged&quot;]
-                    for record in records
-                ]
-            ),
-            sum([record[&quot;total&quot;] for record in records]),
-        )
-        if self.usesCurses:
-            self.window.hline(y, x, &quot;-&quot;, self.formatWidth - 2)
-            y += 1
-            self.window.addstr(y, x, s)
-            x += len(s) + 4
-            s = &quot;{:&gt;10}&quot;.format(&quot;OVERLOADED&quot; if data[&quot;overloaded&quot;] else &quot;&quot;)
-            self.window.addstr(
-                y, x, s,
-                curses.color_pair(1) + curses.A_BOLD if data[&quot;overloaded&quot;] else curses.A_NORMAL
-            )
-        else:
-            if data[&quot;overloaded&quot;]:
-                s += &quot;    OVERLOADED&quot;
-            print(s)
-            print(&quot;&quot;)
-        y += 1
</del><ins>+        items = [&quot; {} - {}&quot;.format(keypress, wtype.help) for keypress, wtype in Dashboard.registered_windows.items()]
+        items.append(&quot;&quot;)
+        items.extend([&quot; {} - {}&quot;.format(key, value[0]) for key, value in Dashboard.registered_window_sets.items() if value[1]])
+        items.extend(self.helpItems)
</ins><span class="cx"> 
</span><ins>+        for item in items:
+            self.tableRow(item, pt)
+
</ins><span class="cx">         if self.usesCurses:
</span><span class="cx">             self.window.refresh()
</span><span class="cx"> 
</span><del>-        self.lastResult = records
</del><span class="cx"> 
</span><span class="cx"> 
</span><del>-
</del><span class="cx"> class SystemWindow(BaseWindow):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Displays the system information provided by the server.
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-    help = &quot;system details&quot;
</del><ins>+    help = &quot;System Status&quot;
</ins><span class="cx">     clientItem = &quot;stats_system&quot;
</span><span class="cx"> 
</span><span class="cx">     windowTitle = &quot;System&quot;
</span><span class="lines">@@ -911,23 +736,8 @@
</span><span class="cx">             return
</span><span class="cx">         self.iter += 1
</span><span class="cx"> 
</span><del>-        if self.usesCurses:
-            self.window.erase()
-            self.window.border()
-            self.window.addstr(
-                0, 2,
-                self.title + &quot; {} ({})&quot;.format(len(records), self.iter)
-            )
-
-        x = 1
-        y = 1
</del><span class="cx">         s = &quot; {:&lt;30}{:&gt;18} &quot;.format(&quot;Item&quot;, &quot;Value&quot;)
</span><del>-        if self.usesCurses:
-            self.window.addstr(y, x, s, curses.A_REVERSE)
-        else:
-            print(&quot;------------ {}&quot;.format(self.title))
-            print(s)
-        y += 1
</del><ins>+        pt = self.tableHeader((s,), len(records))
</ins><span class="cx"> 
</span><span class="cx">         records[&quot;cpu use&quot;] = &quot;{:.2f}&quot;.format(records[&quot;cpu use&quot;])
</span><span class="cx">         records[&quot;memory percent&quot;] = &quot;{:.1f}&quot;.format(records[&quot;memory percent&quot;])
</span><span class="lines">@@ -944,21 +754,11 @@
</span><span class="cx">                 item in self.lastResult and self.lastResult[item] != value
</span><span class="cx">             )
</span><span class="cx">             s = &quot; {:&lt;30}{:&gt;18} &quot;.format(item, value)
</span><del>-            try:
-                if self.usesCurses:
-                    self.window.addstr(
-                        y, x, s,
-                        curses.A_REVERSE if changed else curses.A_NORMAL
-                    )
-                else:
-                    print(s)
-            except curses.error:
-                pass
-            y += 1
</del><ins>+            self.tableRow(
+                s, pt,
+                curses.A_REVERSE if changed else curses.A_NORMAL,
+            )
</ins><span class="cx"> 
</span><del>-        if not self.usesCurses:
-            print(&quot;&quot;)
-
</del><span class="cx">         if self.usesCurses:
</span><span class="cx">             self.window.refresh()
</span><span class="cx"> 
</span><span class="lines">@@ -971,7 +771,7 @@
</span><span class="cx">     Displays the status of the server's master process worker slave slots.
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-    help = &quot;server request stats&quot;
</del><ins>+    help = &quot;HTTP Requests&quot;
</ins><span class="cx">     clientItem = &quot;stats&quot;
</span><span class="cx"> 
</span><span class="cx">     windowTitle = &quot;Request Statistics&quot;
</span><span class="lines">@@ -986,27 +786,14 @@
</span><span class="cx">         records = defaultIfNone(self.clientData(), {})
</span><span class="cx">         self.iter += 1
</span><span class="cx"> 
</span><del>-        if self.usesCurses:
-            self.window.erase()
-            self.window.border()
-            self.window.addstr(0, 2, self.title + &quot; {} ({})&quot;.format(len(records), self.iter,))
-
-        x = 1
-        y = 1
</del><span class="cx">         s1 = &quot; {:&lt;8}{:&gt;8}{:&gt;10}{:&gt;10}{:&gt;10}{:&gt;10}{:&gt;8}{:&gt;8}{:&gt;8} &quot;.format(
</span><span class="cx">             &quot;Period&quot;, &quot;Reqs&quot;, &quot;Av-Reqs&quot;, &quot;Av-Resp&quot;, &quot;Av-NoWr&quot;, &quot;Max-Resp&quot;, &quot;Slot&quot;, &quot;CPU &quot;, &quot;500's&quot;
</span><span class="cx">         )
</span><span class="cx">         s2 = &quot; {:&lt;8}{:&gt;8}{:&gt;10}{:&gt;10}{:&gt;10}{:&gt;10}{:&gt;8}{:&gt;8}{:&gt;8} &quot;.format(
</span><span class="cx">             &quot;&quot;, &quot;&quot;, &quot;per sec&quot;, &quot;(ms)&quot;, &quot;(ms)&quot;, &quot;(ms)&quot;, &quot;Avg.&quot;, &quot;Avg.&quot;, &quot;&quot;
</span><span class="cx">         )
</span><del>-        if self.usesCurses:
-            self.window.addstr(y, x, s1, curses.A_REVERSE)
-            self.window.addstr(y + 1, x, s2, curses.A_REVERSE)
-        else:
-            print(&quot;------------ {}&quot;.format(self.title))
-            print(s1)
-            print(s2)
-        y += 2
</del><ins>+        pt = self.tableHeader((s1, s2,), len(records))
+
</ins><span class="cx">         for key, seconds in ((&quot;current&quot;, 60,), (&quot;1m&quot;, 60,), (&quot;5m&quot;, 5 * 60,), (&quot;1h&quot;, 60 * 60,),):
</span><span class="cx">             stat = records.get(key, {
</span><span class="cx">                 &quot;requests&quot;: 0,
</span><span class="lines">@@ -1028,18 +815,83 @@
</span><span class="cx">                 safeDivision(stat[&quot;cpu&quot;], stat[&quot;requests&quot;]),
</span><span class="cx">                 stat[&quot;500&quot;],
</span><span class="cx">             )
</span><del>-            try:
-                if self.usesCurses:
-                    self.window.addstr(y, x, s)
-                else:
-                    print(s)
-            except curses.error:
-                pass
-            y += 1
</del><ins>+            self.tableRow(s, pt)
</ins><span class="cx"> 
</span><del>-        if not self.usesCurses:
-            print(&quot;&quot;)
</del><ins>+        if self.usesCurses:
+            self.window.refresh()
</ins><span class="cx"> 
</span><ins>+        self.lastResult = records
+
+
+
+class HTTPSlotsWindow(BaseWindow):
+    &quot;&quot;&quot;
+    Displays the status of the server's master process worker slave slots.
+    &quot;&quot;&quot;
+
+    help = &quot;HTTP Slots&quot;
+    clientItem = &quot;slots&quot;
+
+    windowTitle = &quot;HTTP Slots&quot;
+    formatWidth = 72
+    additionalRows = 5
+
+    def updateRowCount(self):
+        self.rowCount = len(defaultIfNone(self.readItem(self.clientItem), {&quot;slots&quot;: ()})[&quot;slots&quot;])
+
+
+    def update(self):
+        data = defaultIfNone(self.clientData(), {&quot;slots&quot;: {}, &quot;overloaded&quot;: False})
+        records = data[&quot;slots&quot;]
+        if len(records) != self.rowCount:
+            self.needsReset = True
+            return
+        self.iter += 1
+
+        s = &quot; {:&gt;4}{:&gt;8}{:&gt;8}{:&gt;8}{:&gt;8}{:&gt;8}{:&gt;8}{:&gt;8}{:&gt;8} &quot;.format(
+            &quot;Slot&quot;, &quot;unack&quot;, &quot;ack&quot;, &quot;uncls&quot;, &quot;total&quot;,
+            &quot;start&quot;, &quot;strting&quot;, &quot;stopped&quot;, &quot;abd&quot;
+        )
+        pt = self.tableHeader((s,), len(records))
+
+        for record in sorted(records, key=lambda x: x[&quot;slot&quot;]):
+            changed = (
+                record[&quot;slot&quot;] in self.lastResult and
+                self.lastResult[record[&quot;slot&quot;]] != record
+            )
+            s = &quot; {:&gt;4}{:&gt;8}{:&gt;8}{:&gt;8}{:&gt;8}{:&gt;8}{:&gt;8}{:&gt;8}{:&gt;8} &quot;.format(
+                record[&quot;slot&quot;],
+                record[&quot;unacknowledged&quot;],
+                record[&quot;acknowledged&quot;],
+                record[&quot;unclosed&quot;],
+                record[&quot;total&quot;],
+                record[&quot;started&quot;],
+                record[&quot;starting&quot;],
+                record[&quot;stopped&quot;],
+                record[&quot;abandoned&quot;],
+            )
+            count = record[&quot;unacknowledged&quot;] + record[&quot;acknowledged&quot;]
+            self.tableRow(
+                s, pt,
+                curses.A_REVERSE if changed else (
+                    curses.A_BOLD if count else curses.A_NORMAL
+                ),
+            )
+
+        s = &quot; {:&lt;12}{:&gt;8}{:&gt;16}&quot;.format(
+            &quot;Total:&quot;,
+            sum(
+                [
+                    record[&quot;unacknowledged&quot;] + record[&quot;acknowledged&quot;]
+                    for record in records
+                ]
+            ),
+            sum([record[&quot;total&quot;] for record in records]),
+        )
+        if data[&quot;overloaded&quot;]:
+            s += &quot;    OVERLOADED&quot;
+        self.tableFooter((s,), pt)
+
</ins><span class="cx">         if self.usesCurses:
</span><span class="cx">             self.window.refresh()
</span><span class="cx"> 
</span><span class="lines">@@ -1052,13 +904,13 @@
</span><span class="cx">     Display the status of the server's request methods.
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-    help = &quot;server methods&quot;
</del><ins>+    help = &quot;HTTP Methods&quot;
</ins><span class="cx">     clientItem = &quot;stats&quot;
</span><span class="cx">     stats_keys = (&quot;current&quot;, &quot;1m&quot;, &quot;5m&quot;, &quot;1h&quot;,)
</span><span class="cx"> 
</span><span class="cx">     windowTitle = &quot;Methods&quot;
</span><span class="cx">     formatWidth = 116
</span><del>-    additionalRows = 7
</del><ins>+    additionalRows = 8
</ins><span class="cx"> 
</span><span class="cx">     def updateRowCount(self):
</span><span class="cx">         stats = defaultIfNone(self.clientData(), {})
</span><span class="lines">@@ -1074,6 +926,9 @@
</span><span class="cx">         methods = set()
</span><span class="cx">         for key in self.stats_keys:
</span><span class="cx">             methods.update(stats.get(key, {}).get(&quot;method&quot;, {}).keys())
</span><ins>+        if len(methods) != self.rowCount:
+            self.needsReset = True
+            return
</ins><span class="cx"> 
</span><span class="cx">         records = {}
</span><span class="cx">         records_t = {}
</span><span class="lines">@@ -1082,16 +937,6 @@
</span><span class="cx">             records_t[key] = defaultIfNone(self.clientData(), {}).get(key, {}).get(&quot;method-t&quot;, {})
</span><span class="cx">         self.iter += 1
</span><span class="cx"> 
</span><del>-        if self.usesCurses:
-            self.window.erase()
-            self.window.border()
-            self.window.addstr(
-                0, 2,
-                self.title + &quot; {} ({})&quot;.format(len(records), self.iter)
-            )
-
-        x = 1
-        y = 1
</del><span class="cx">         s1 = &quot; {:&lt;40}{:&gt;8}{:&gt;10}{:&gt;8}{:&gt;10}{:&gt;8}{:&gt;10}{:&gt;8}{:&gt;10} &quot;.format(
</span><span class="cx">             &quot;&quot;, &quot;------&quot;, &quot;current---&quot;, &quot;------&quot;, &quot;1m--------&quot;, &quot;------&quot;, &quot;5m--------&quot;, &quot;------&quot;, &quot;1h--------&quot;,
</span><span class="cx">         )
</span><span class="lines">@@ -1101,16 +946,8 @@
</span><span class="cx">         s3 = &quot; {:&lt;40}{:&gt;8}{:&gt;10}{:&gt;8}{:&gt;10}{:&gt;8}{:&gt;10}{:&gt;8}{:&gt;10} &quot;.format(
</span><span class="cx">             &quot;&quot;, &quot;&quot;, &quot;(ms)&quot;, &quot;&quot;, &quot;(ms)&quot;, &quot;&quot;, &quot;(ms)&quot;, &quot;&quot;, &quot;(ms)&quot;,
</span><span class="cx">         )
</span><del>-        if self.usesCurses:
-            self.window.addstr(y, x, s1, curses.A_REVERSE)
-            self.window.addstr(y + 1, x, s2, curses.A_REVERSE)
-            self.window.addstr(y + 2, x, s3, curses.A_REVERSE)
-        else:
-            print(&quot;------------ {}&quot;.format(self.title))
-            print(s1)
-            print(s2)
-            print(s3)
-        y += 2
</del><ins>+        pt = self.tableHeader((s1, s2, s3,), len(records))
+
</ins><span class="cx">         total_methods = dict([(key, 0) for key in self.stats_keys])
</span><span class="cx">         total_time = dict([(key, 0.0) for key in self.stats_keys])
</span><span class="cx">         for method_type in sorted(methods):
</span><span class="lines">@@ -1125,17 +962,10 @@
</span><span class="cx">             s = &quot; {:&lt;40}{:&gt;8}{:&gt;10.1f}{:&gt;8}{:&gt;10.1f}{:&gt;8}{:&gt;10.1f}{:&gt;8}{:&gt;10.1f} &quot;.format(
</span><span class="cx">                 *items
</span><span class="cx">             )
</span><del>-            try:
-                if self.usesCurses:
-                    self.window.addstr(
-                        y, x, s,
-                        curses.A_REVERSE if changed else curses.A_NORMAL,
-                    )
-                else:
-                    print(s)
-            except curses.error:
-                pass
-            y += 1
</del><ins>+            self.tableRow(
+                s, pt,
+                curses.A_REVERSE if changed else curses.A_NORMAL,
+            )
</ins><span class="cx"> 
</span><span class="cx">         items = [&quot;Total:&quot;]
</span><span class="cx">         for key in self.stats_keys:
</span><span class="lines">@@ -1151,17 +981,7 @@
</span><span class="cx">         s2 = &quot; {:&lt;40}{:&gt;8}{:&gt;10}{:&gt;8}{:&gt;10}{:&gt;8}{:&gt;10}{:&gt;8}{:&gt;10} &quot;.format(
</span><span class="cx">             *items
</span><span class="cx">         )
</span><del>-        if self.usesCurses:
-            self.window.hline(y, x, &quot;-&quot;, self.formatWidth - 2)
-            y += 1
-            self.window.addstr(y, x, s1)
-            y += 1
-            self.window.addstr(y, x, s2)
-        else:
-            print(s1)
-            print(s2)
-            print(&quot;&quot;)
-        y += 1
</del><ins>+        self.tableFooter((s1, s2,), pt)
</ins><span class="cx"> 
</span><span class="cx">         if self.usesCurses:
</span><span class="cx">             self.window.refresh()
</span><span class="lines">@@ -1170,12 +990,160 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+class AssignmentsWindow(BaseWindow):
+    &quot;&quot;&quot;
+    Displays the status of the server's master process worker slave slots.
+    &quot;&quot;&quot;
+
+    help = &quot;Job Assignments&quot;
+    clientItem = &quot;job_assignments&quot;
+
+    windowTitle = &quot;Job Assignments&quot;
+    formatWidth = 40
+    additionalRows = 5
+
+    def updateRowCount(self):
+        self.rowCount = len(defaultIfNone(self.readItem(self.clientItem), {&quot;workers&quot;: ()})[&quot;workers&quot;])
+
+
+    def update(self):
+        data = defaultIfNone(self.clientData(), {&quot;workers&quot;: {}, &quot;level&quot;: 0})
+        records = data[&quot;workers&quot;]
+        if len(records) != self.rowCount:
+            self.needsReset = True
+            return
+        self.iter += 1
+
+        s = &quot; {:&gt;4}{:&gt;12}{:&gt;8}{:&gt;12} &quot;.format(
+            &quot;Slot&quot;, &quot;assigned&quot;, &quot;load&quot;, &quot;completed&quot;
+        )
+        pt = self.tableHeader((s,), len(records))
+
+        total_assigned = 0
+        total_completed = 0
+        for ctr, details in enumerate(records):
+            assigned, load, completed = details
+            total_assigned += assigned
+            total_completed += completed
+            changed = (
+                ctr in self.lastResult and
+                self.lastResult[ctr] != assigned
+            )
+            s = &quot; {:&gt;4}{:&gt;12}{:&gt;8}{:&gt;12} &quot;.format(
+                ctr,
+                assigned,
+                load,
+                completed,
+            )
+            self.tableRow(
+                s, pt,
+                curses.A_REVERSE if changed else curses.A_NORMAL,
+            )
+
+        s = &quot; {:&lt;6}{:&gt;10}{:&gt;8}{:&gt;12}&quot;.format(
+            &quot;Total:&quot;,
+            total_assigned,
+            &quot;{}%&quot;.format(data[&quot;level&quot;]),
+            total_completed,
+        )
+        self.tableFooter((s,), pt)
+
+        if self.usesCurses:
+            self.window.refresh()
+
+        self.lastResult = records
+
+
+
+class JobsWindow(BaseWindow):
+    &quot;&quot;&quot;
+    Display the status of the server's job queue.
+    &quot;&quot;&quot;
+
+    help = &quot;Job Activity&quot;
+    clientItem = &quot;jobs&quot;
+
+    windowTitle = &quot;Jobs&quot;
+    formatWidth = 98
+    additionalRows = 6
+
+    def updateRowCount(self):
+        self.rowCount = defaultIfNone(self.readItem(&quot;jobcount&quot;), 0)
+
+
+    def update(self):
+        records = defaultIfNone(self.clientData(), {})
+        if len(records) != self.rowCount:
+            self.needsReset = True
+            return
+        self.iter += 1
+
+        s1 = &quot; {:&lt;40}{:&gt;8}{:&gt;10}{:&gt;8}{:&gt;8}{:&gt;10}{:&gt;10} &quot;.format(
+            &quot;Work Type&quot;, &quot;Queued&quot;, &quot;Assigned&quot;, &quot;Late&quot;, &quot;Failed&quot;, &quot;Completed&quot;, &quot;Av-Time&quot;,
+        )
+        s2 = &quot; {:&lt;40}{:&gt;8}{:&gt;10}{:&gt;8}{:&gt;8}{:&gt;10}{:&gt;10} &quot;.format(
+            &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;(ms)&quot;,
+        )
+        pt = self.tableHeader((s1, s2,), len(records))
+
+        total_queued = 0
+        total_assigned = 0
+        total_late = 0
+        total_failed = 0
+        total_completed = 0
+        total_time = 0.0
+        for work_type, details in sorted(records.items(), key=lambda x: x[0]):
+            total_queued += details[&quot;queued&quot;]
+            total_assigned += details[&quot;assigned&quot;]
+            total_late += details[&quot;late&quot;]
+            total_failed += details[&quot;failed&quot;]
+            total_completed += details[&quot;completed&quot;]
+            total_time += details[&quot;time&quot;]
+            changed = (
+                work_type in self.lastResult and
+                self.lastResult[work_type][&quot;queued&quot;] != details[&quot;queued&quot;]
+            )
+            s = &quot;{}{:&lt;40}{:&gt;8}{:&gt;10}{:&gt;8}{:&gt;8}{:&gt;10}{:&gt;10.1f} &quot;.format(
+                &quot;&gt;&quot; if details[&quot;queued&quot;] else &quot; &quot;,
+                work_type,
+                details[&quot;queued&quot;],
+                details[&quot;assigned&quot;],
+                details[&quot;late&quot;],
+                details[&quot;failed&quot;],
+                details[&quot;completed&quot;],
+                safeDivision(details[&quot;time&quot;], details[&quot;completed&quot;], 1000.0)
+            )
+            self.tableRow(
+                s, pt,
+                curses.A_REVERSE if changed else (
+                    curses.A_BOLD if details[&quot;queued&quot;] else curses.A_NORMAL
+                ),
+            )
+
+        s = &quot; {:&lt;40}{:&gt;8}{:&gt;10}{:&gt;8}{:&gt;8}{:&gt;10}{:&gt;10.1f} &quot;.format(
+            &quot;Total:&quot;,
+            total_queued,
+            total_assigned,
+            total_late,
+            total_failed,
+            total_completed,
+            safeDivision(total_time, total_completed, 1000.0)
+        )
+        self.tableFooter((s,), pt)
+
+        if self.usesCurses:
+            self.window.refresh()
+
+        self.lastResult = records
+
+
+
</ins><span class="cx"> class DirectoryStatsWindow(BaseWindow):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Displays the status of the server's directory service calls
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-    help = &quot;directory service stats&quot;
</del><ins>+    help = &quot;Directory Service&quot;
</ins><span class="cx">     clientItem = &quot;directory&quot;
</span><span class="cx"> 
</span><span class="cx">     windowTitle = &quot;Directory Service&quot;
</span><span class="lines">@@ -1194,27 +1162,13 @@
</span><span class="cx"> 
</span><span class="cx">         self.iter += 1
</span><span class="cx"> 
</span><del>-        if self.usesCurses:
-            self.window.erase()
-            self.window.border()
-            self.window.addstr(0, 2, self.title + &quot; {} ({})&quot;.format(len(records), self.iter,))
-
-        x = 1
-        y = 1
</del><span class="cx">         s1 = &quot; {:&lt;40}{:&gt;15}{:&gt;15}{:&gt;15} &quot;.format(
</span><span class="cx">             &quot;Method&quot;, &quot;Calls&quot;, &quot;Total&quot;, &quot;Average&quot;
</span><span class="cx">         )
</span><span class="cx">         s2 = &quot; {:&lt;40}{:&gt;15}{:&gt;15}{:&gt;15} &quot;.format(
</span><span class="cx">             &quot;&quot;, &quot;&quot;, &quot;(sec)&quot;, &quot;(ms)&quot;
</span><span class="cx">         )
</span><del>-        if self.usesCurses:
-            self.window.addstr(y, x, s1, curses.A_REVERSE)
-            self.window.addstr(y + 1, x, s2, curses.A_REVERSE)
-        else:
-            print(&quot;------------ {}&quot;.format(self.title))
-            print(s1)
-            print(s2)
-        y += 2
</del><ins>+        pt = self.tableHeader((s1, s2,), len(records))
</ins><span class="cx"> 
</span><span class="cx">         overallCount = 0
</span><span class="cx">         overallCountRatio = 0
</span><span class="lines">@@ -1242,14 +1196,7 @@
</span><span class="cx">                 timeSpent,
</span><span class="cx">                 (1000.0 * timeSpent) / count,
</span><span class="cx">             )
</span><del>-            try:
-                if self.usesCurses:
-                    self.window.addstr(y, x, s)
-                else:
-                    print(s)
-            except curses.error:
-                pass
-            y += 1
</del><ins>+            self.tableRow(s, pt)
</ins><span class="cx"> 
</span><span class="cx">         s = &quot; {:&lt;40}{:&gt;15d}{:&gt;15.1f}{:&gt;15.3f} &quot;.format(
</span><span class="cx">             &quot;Total:&quot;,
</span><span class="lines">@@ -1269,18 +1216,7 @@
</span><span class="cx">             safeDivision(overallCountUncached, overallCountRatio, 100.0),
</span><span class="cx">             &quot;&quot;,
</span><span class="cx">         )
</span><del>-        if self.usesCurses:
-            self.window.hline(y, x, &quot;-&quot;, self.formatWidth - 2)
-            y += 1
-            self.window.addstr(y, x, s)
-            self.window.addstr(y + 1, x, s_cached)
-            self.window.addstr(y + 2, x, s_uncached)
-        else:
-            print(s)
-            print(s1)
-            print(s2)
-            print(&quot;&quot;)
-        y += 3
</del><ins>+        self.tableFooter((s, s_cached, s_uncached), pt)
</ins><span class="cx"> 
</span><span class="cx">         if self.usesCurses:
</span><span class="cx">             self.window.refresh()
</span></span></pre>
</div>
</div>

</body>
</html>