[Git][NTPsec/ntpsec][wip-ntpq-peers-display] ntpmon now has unit display.

Ian Bruene gitlab at mg.gitlab.com
Mon Mar 27 17:27:33 UTC 2017


Ian Bruene pushed to branch wip-ntpq-peers-display at NTPsec / ntpsec


Commits:
9ed7754a by Ian Bruene at 2017-03-27T12:26:18-05:00
ntpmon now has unit display.

ntp.util now has global lists of variables that use units (incomplete)

- - - - -


2 changed files:

- ntpclients/ntpmon
- pylib/util.py


Changes:

=====================================
ntpclients/ntpmon
=====================================
--- a/ntpclients/ntpmon
+++ b/ntpclients/ntpmon
@@ -13,6 +13,7 @@ Any keystroke causes a poll and update. Keystroke commands:
 'p': Change peer display to default mode, showing refid.
 'q': Cleanly terminate the program.
 's': Toggle display of only reachable hosts (default is all hosts).
+'u': Toggle display of units.
 'w': Toggle wide mode.
 'x': Cleanly terminate the program.
 ' ': Rotate through a/n/o/p display modes.
@@ -70,7 +71,18 @@ def statline(_peerlist, _mrulist, nyquist):
     return leader + spacer + trailer
 
 
-def peer_detail(variables):
+def filtcooker(data):
+    "Cooks the string of space seperated numbers with units"
+    parts = data.split()
+    cooked = []
+    for part in parts:
+        part = float(part)
+        cooked.append(ntp.util.f8unit(part, ntp.util.UNIT_MS))
+    rendered = "".join(cooked)
+    return rendered
+
+
+def peer_detail(variables, showunits=False):
     "Show the things a peer summary doesn't, cooked slightly differently"
     # All of an rv display except refid, reach, delay, offset, jitter.
     # One of the goals here is to emit field values at fixed positions
@@ -84,14 +96,27 @@ def peer_detail(variables):
             vcopy[fld] = "***missing***"
         else:
             vcopy[fld] = ntp.util.rfc3339(ntp.ntpc.lfptofloat(vcopy[fld]))
-    vcopy['filtdelay'] = vcopy['filtdelay'].replace(' ', '\t')
-    vcopy['filtoffset'] = vcopy['filtoffset'].replace(' ', '\t')
-    vcopy['filtdisp'] = vcopy['filtdisp'].replace(' ', '\t')
+    if showunits:
+        for name in ntp.util.MS_VARS:
+            if name in vcopy:
+                vcopy[name] = ntp.util.f8unit(vcopy[name],
+                                              ntp.util.UNIT_MS,
+                                              True)
+        for name in ntp.util.PPM_VARS:
+            if name in vcopy:
+                vcopy[name] = ntp.util.ppmformathack(vcopy[name], True)
+        vcopy['filtdelay'] = filtcooker(vcopy['filtdelay'])
+        vcopy['filtoffset'] = filtcooker(vcopy['filtoffset'])
+        vcopy['filtdisp'] = filtcooker(vcopy['filtdisp'])
+    else:
+        vcopy['filtdelay'] = vcopy['filtdelay'].replace(' ', '\t')
+        vcopy['filtoffset'] = vcopy['filtoffset'].replace(' ', '\t')
+        vcopy['filtdisp'] = vcopy['filtdisp'].replace(' ', '\t')
     peerfmt = """\
 srcadr=%(srcadr)s, srcport=%(srcport)d, dstadr=%(dstadr)s, dstport=%(dstport)s
 leap=%(leap)s\treftime=%(reftime)s\trootdelay=%(rootdelay)s
 stratum=%(stratum)2d\trec=%(rec)s\trootdisp=%(rootdisp)s
-precision=%(precision)3d\txmt=%(xmt)s\tdispersion=%(dispersion)6.6f
+precision=%(precision)3d\txmt=%(xmt)s\tdispersion=%(dispersion)s
 unreach=%(unreach)d, hmode=%(hmode)d, pmode=%(pmode)d, hpoll=%(hpoll)d, ppoll=%(ppoll)d, headway=%(headway)s, flash=%(flash)s, keyid=%(keyid)s
 filtdelay  = %(filtdelay)s
 filtoffset = %(filtoffset)s
@@ -148,6 +173,7 @@ if __name__ == '__main__':
     wideremote = False
     showall = True
     showpeers = True
+    showunits = False
     nyquist = 1
 
     for (switch, val) in options:
@@ -162,6 +188,7 @@ if __name__ == '__main__':
                                        pktversion=ntp.magic.NTP_VERSION,
                                        showhostnames=showhostnames,
                                        wideremote=wideremote,
+                                       showunits=showunits,
                                        termwidth=80,
                                        debug=0)
     mru_report = ntp.util.MRUSummary(showhostnames)
@@ -252,7 +279,7 @@ if __name__ == '__main__':
                                                     peers[selected].status)
                             stdscr.addstr("assoc=%d: %s\n"
                                           % (peers[selected].associd, sw))
-                            stdscr.addstr(peer_detail(retained))
+                            stdscr.addstr(peer_detail(retained, showunits))
                             try:
                                 clockvars = session.readvar(
                                     peers[selected].associd,
@@ -295,6 +322,9 @@ if __name__ == '__main__':
                         peer_report.displaymode = 'peers'
                     elif key == 's':
                         showall = not showall
+                    elif key == 'u':
+                        showunits = not showunits
+                        peer_report.showunits = showunits
                     elif key == 'w':
                         peer_report.wideremote = not peer_report.wideremote
                     elif key == " ":


=====================================
pylib/util.py
=====================================
--- a/pylib/util.py
+++ b/pylib/util.py
@@ -38,6 +38,15 @@ UNIT_KS = 4
 UNITS = ["ns", "us", "ms", "s ", "ks"]
 
 
+# Variables that have units
+MS_VARS = ("rootdelay", "rootdisp", "offset", "sys_jitter", "clk_jitter",
+           "leapsmearoffset", "authdelay", "koffset", "kmaxerr", "kesterr",
+           "kprecis", "kppsjitter", "fuzz", "clk_wander_threshold", "tick",
+           "in", "out", "bias", "delay", "jitter", "dispersion",
+           "fudgetime1", "fudgetime2")
+PPM_VARS = ("frequency", "clk_wander", "clk_wander_threshold")
+
+
 def stdversion():
     return "%s-%s+%s %s" % (ntp.version.VCS_BASENAME,
                             ntp.version.VERSION,
@@ -340,12 +349,7 @@ def cook(variables, showunits=False):
                     if (1 << i) & value:
                         item += tstflagnames[i] + " "
                 item = item[:-1]
-        elif name in ("rootdelay", "rootdisp", "offset", "sys_jitter",
-                      "clk_jitter", "leapsmearoffset", "authdelay",
-                      "koffset", "kmaxerr", "kesterr", "kprecis",
-                      "kppsjitter", "fuzz", "clk_wander_threshold",
-                      "tick", "in", "out", "bias", "delay", "jitter",
-                      "dispersion", "fudgetime1", "fudgetime2"):
+        elif name in MS_VARS:
             #  Note that this is *not* complete, there are definitely
             #   missing variables here, and other units (ppm).
             #  Completion cannot occur until all units are tracked down.
@@ -353,7 +357,7 @@ def cook(variables, showunits=False):
                 item += f8unit(value, UNIT_MS, True)
             else:
                 item += repr(value)
-        elif name in ("frequency", "clk_wander", "clk_wander_threshold"):
+        elif name in PPM_VARS:
             item += ppmformathack(value, True)
         else:
             item += repr(value)



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/9ed7754abed08bddcdb6905851043d4fb41a3013
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170327/ca376ba7/attachment.html>


More information about the vc mailing list