[Git][NTPsec/ntpsec][master] 4 commits: Correct display of peer status word in ntpmon.
Eric S. Raymond
gitlab at mg.gitlab.com
Sun Dec 18 14:49:52 UTC 2016
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
bca17b6e by Eric S. Raymond at 2016-12-18T05:54:49-05:00
Correct display of peer status word in ntpmon.
- - - - -
4b3ded43 by Eric S. Raymond at 2016-12-18T09:06:30-05:00
In ntpmon, tabularize the detail display.
- - - - -
3c56bb44 by Eric S. Raymond at 2016-12-18T09:37:42-05:00
Prevent scrolling in the ntpmon display.
- - - - -
a79bb50f by Eric S. Raymond at 2016-12-18T09:49:22-05:00
Documentation polishing.
- - - - -
3 changed files:
- docs/includes/ntpmon-body.txt
- ntpclients/ntpmon
- pylib/util.py
Changes:
=====================================
docs/includes/ntpmon-body.txt
=====================================
--- a/docs/includes/ntpmon-body.txt
+++ b/docs/includes/ntpmon-body.txt
@@ -22,6 +22,13 @@ The status bar includes the version string of the server being
watched, the (local) time at which it was last updated, and the
current query interval.
+There is a detail-display mode that dumps full information about a
+single selected peer in a tabular format that makes it relatively easy
+to see changing values. However, note that a default-sized terminal
+emulator window (usually 25 lines) doesn't have enough room for the
+clock variables portion. The only fix for this is to resize your
+terminal.
+
^C cleanly terminates the program. Any keystroke will trigger a poll
and update. A few single-keystroke commands are also interpreted as
commands.
=====================================
ntpclients/ntpmon
=====================================
--- a/ntpclients/ntpmon
+++ b/ntpclients/ntpmon
@@ -63,6 +63,32 @@ def statline(_peerlist, _mrulist, nyquist):
spacer = (peer_report.termwidth - len(leader) - len(trailer)) * " "
return leader + spacer + trailer
+def peer_detail(variables):
+ "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
+ # on the 2D display, so that changes in the details are easier to spot.
+ vcopy = {}
+ vcopy.update(variables)
+ vcopy["leap"] = ("no-leap", "add-leap", "del-leap", "unsync")[vcopy["leap"]]
+ vcopy['xmt'] = ntp.util.rfc3339(ntp.ntpc.lfptofloat(vcopy['xmt']))
+ vcopy['rec'] = ntp.util.rfc3339(ntp.ntpc.lfptofloat(vcopy['rec']))
+ vcopy['reftime'] = ntp.util.rfc3339(ntp.ntpc.lfptofloat(vcopy['reftime']))
+ 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
+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
+filtdisp = %(filtdisp)s
+"""
+ return peerfmt % vcopy
+
class Fatal(Exception):
"Unrecoverable error."
def __init__(self, msg):
@@ -80,6 +106,9 @@ class OutputContext:
curses.cbreak()
curses.noecho()
stdscr.keypad(True)
+ # Design decision: The most important info is nearer the
+ # top of the display. Therefore, prevent scrolling.
+ stdscr.scrollok(False)
def __exit__(self, extype_unused, value_unused, traceback_unused):
curses.endwin()
@@ -185,13 +214,17 @@ if __name__ == '__main__':
sl = statline(peer_report, mru_report, nyquist)
stdscr.addstr(sl + "\n", curses.A_REVERSE|curses.A_DIM)
if detailmode:
- sw = ntp.util.PeerStatusWord(peers[i].status)
- stdscr.addstr("assoc=%d, %s\n" \
+ if ntp.util.PeerSummary.is_clock(retained):
+ dtype = ntp.ntpc.TYPE_CLOCK
+ else:
+ dtype = ntp.ntpc.TYPE_PEER
+ sw = ntp.ntpc.statustoa(dtype, peers[i].status)
+ stdscr.addstr("assoc=%d: %s\n" \
% (peers[i].associd, sw))
- stdscr.addstr("\n" + ntp.util.cook(retained))
+ stdscr.addstr(peer_detail(retained))
try:
clockvars = session.readvar(peer.associd, opcode=ntp.control.CTL_OP_READCLOCK)
- stdscr.addstr("\n" + ntp.util.cook(clockvars))
+ stdscr.addstr(ntp.util.cook(clockvars))
except ntp.packet.ControlException:
pass
elif span.entries:
=====================================
pylib/util.py
=====================================
--- a/pylib/util.py
+++ b/pylib/util.py
@@ -111,7 +111,7 @@ def termsize():
return TermSize(*size)
class PeerStatusWord:
- "A peer status wor dissected for display"
+ "A peer status word from readstats(), dissected for display"
def __init__(self, status, pktversion=ntp.magic.NTP_VERSION):
self.event = ntp.control.CTL_PEER_EVENT(status)
self.event_count = ntp.control.CTL_PEER_NEVNT(status)
@@ -292,6 +292,11 @@ class PeerSummary:
else:
return '-' + hostname[-maxlen+1:]
+ @staticmethod
+ def is_clock(variables):
+ "Does a set of variables look like it returned from a clock?"
+ return "srchost" in variables and '(' in variables["srchost"]
+
def header(self):
"Column headers for peer display"
if self.displaymode == "apeers":
@@ -383,7 +388,7 @@ class PeerSummary:
else:
ptype = 'B'
elif hmode == ntp.magic.MODE_CLIENT:
- if srchost and '(' in srchost:
+ if PeerSummary.is_clock(variables):
ptype = 'l' # local refclock
elif dstadr_refid == "POOL":
ptype = 'p' # pool
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/62564b05a8da0687a06da85010ca79218cd63fa3...a79bb50f3108e306a96e1bf67e9211b315d3ef20
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20161218/47162a40/attachment.html>
More information about the vc
mailing list