[Git][NTPsec/ntpsec][master] 2 commits: ntp.util: Shorten ntpq/ntpmon peers common output generation.
James Browning
gitlab at mg.gitlab.com
Sat Feb 13 16:44:35 UTC 2021
James Browning pushed to branch master at NTPsec / ntpsec
Commits:
8ad6038b by JamesB192 at 2021-02-13T16:33:21+00:00
ntp.util: Shorten ntpq/ntpmon peers common output generation.
- - - - -
fae7938a by JamesB192 at 2021-02-13T16:33:21+00:00
ntpq, ntpmon: Add dextral peers mode ...
Putting the peer and peer status word on the right.
- - - - -
5 changed files:
- docs/includes/ntpmon-body.adoc
- docs/includes/ntpq-body.adoc
- ntpclients/ntpmon.py
- ntpclients/ntpq.py
- pylib/util.py
Changes:
=====================================
docs/includes/ntpmon-body.adoc
=====================================
@@ -69,6 +69,9 @@ p:: Change peer display to default mode, showing refid.
q:: Cleanly terminate the program.
+r:: Change to dextral mode, identical to 'p' save that the refid, tally \
+and remote clock are on the right.
+
s:: Toggle display of only reachable hosts (default is all hosts).
u:: Toggle display of units for time values. (default is off)
=====================================
docs/includes/ntpq-body.adoc
=====================================
@@ -389,6 +389,12 @@ where the output is just like the +peers+ command except that the
+refid+ is displayed in hex format and the association number is also
displayed.
++rpeers+::
+ Display a list of peers in the form
++
++st t when pool reach delay offset jitter refid tally remote+
++
+
+pstats+ _assocID_::
Show the statistics for the peer with the given _assocID_.
=====================================
ntpclients/ntpmon.py
=====================================
@@ -19,7 +19,7 @@ Any keystroke causes a poll and update. Keystroke commands:
'u': Toggle display of units.
'w': Toggle wide mode.
'x': Cleanly terminate the program.
-' ': Rotate through a/n/o/p display modes.
+' ': Rotate through a/n/o/p/r display modes.
'+': Increase debugging level. Output goes to ntpmon.log
'-': Decrease debugging level.
'?': Display helpscreen.
@@ -438,6 +438,8 @@ if __name__ == '__main__':
peer_report.displaymode = 'opeers'
elif key == 'p':
peer_report.displaymode = 'peers'
+ elif key == 'r':
+ peer_report.displaymode = 'rpeers'
elif key == 's':
showall = not showall
elif key == 'u':
@@ -452,6 +454,8 @@ if __name__ == '__main__':
peer_report.displaymode = 'apeers'
elif peer_report.displaymode == 'apeers':
peer_report.displaymode = 'opeers'
+ elif peer_report.displaymode == 'opeers':
+ peer_report.displaymode = 'rpeers'
else:
peer_report.displaymode = 'peers'
elif key == 'j' or key == "KEY_DOWN":
=====================================
ntpclients/ntpq.py
=====================================
@@ -1112,6 +1112,16 @@ usage: pstats assocID
self.say("""\
function: obtain and print a list of the server's peers [IP version]
usage: peers
+""")
+
+ def do_rpeers(self, line):
+ "obtain and print a list of the server's peers (dextral)"
+ self.__dopeers(showall=True, mode="rpeers")
+
+ def help_rpeers(self):
+ self.say("""\
+function: obtain and print a list of the server's peers (dextral)
+usage: rpeers
""")
def do_apeers(self, line):
=====================================
pylib/util.py
=====================================
@@ -937,6 +937,9 @@ class PeerSummary:
self.__header = self.__remote + \
" local ".ljust(self.refidwidth) + \
self.__common + " disp"
+ elif self.displaymode == 'rpeers':
+ self.__header = ' st t when poll reach delay ' + \
+ 'offset jitter refid T remote'
else:
self.__header = self.__remote + \
" refid ".ljust(self.refidwidth) + \
@@ -1159,12 +1162,13 @@ class PeerSummary:
clock_name = srcadr
else:
clock_name = ""
- if self.wideremote and len(clock_name) > self.namewidth:
- line += ("%c%s\n" % (c, clock_name))
- line += (" " * (self.namewidth + 2))
- else:
- line += ("%c%-*.*s " % (c, self.namewidth, self.namewidth,
- clock_name[:self.namewidth]))
+ if self.displaymode != "rpeers":
+ if self.wideremote and len(clock_name) > self.namewidth:
+ line += ("%c%s\n" % (c, clock_name))
+ line += (" " * (self.namewidth + 2))
+ else:
+ line += ("%c%-*.*s " % (c, self.namewidth, self.namewidth,
+ clock_name[:self.namewidth]))
# Destination address, assoc ID or refid.
assocwidth = 7 if self.displaymode == "apeers" else 0
if "." not in dstadr_refid and ":" not in dstadr_refid:
@@ -1173,45 +1177,29 @@ class PeerSummary:
visible = "..."
else:
visible = dstadr_refid
- line += self.high_truncate(visible, self.refidwidth)
- if self.displaymode == "apeers":
- line += (" " * (self.refidwidth - len(visible) - assocwidth + 1))
- line += ("%-6d" % (associd))
- else:
- line += (" " * (self.refidwidth - len(visible)))
+ if self.displaymode != "rpeers":
+ line += self.high_truncate(visible, self.refidwidth)
+ if self.displaymode == "apeers":
+ line += (" " * (self.refidwidth - len(visible) - assocwidth + 1))
+ line += ("%-6d" % (associd))
+ else:
+ line += (" " * (self.refidwidth - len(visible)))
# The rest of the story
if last_sync is None:
last_sync = now
jd = estjitter if have_jitter else estdisp
+ if self.showunits:
+ fini = lambda x : unitify(x, UNIT_MS)
+ elif saw6:
+ fini = lambda x : f8dot4(x)
+ else:
+ fini = lambda x : f8dot3(x)
line += (
- " %2ld %c %4.4s %4.4s %3lo"
+ " %2ld %c %4.4s %4.4s %3lo %s %s %s"
% (stratum, ptype,
PeerSummary.prettyinterval(last_sync),
- PeerSummary.prettyinterval(poll_sec), reach))
- if saw6:
- if self.showunits:
- line += (
- " %s %s %s" %
- (unitify(estdelay, UNIT_MS),
- unitify(estoffset, UNIT_MS),
- unitify(jd, UNIT_MS)))
- else:
- line += (
- " %s %s %s" %
- (f8dot4(estdelay), f8dot4(estoffset), f8dot4(jd)))
- else:
- # old servers only have 3 digits of fraction
- # don't print a fake 4th digit
- if self.showunits:
- line += (
- " %s %s %s" %
- (unitify(estdelay, UNIT_MS),
- unitify(estoffset, UNIT_MS),
- unitify(jd, UNIT_MS)))
- else:
- line += (
- " %s %s %s" %
- (f8dot3(estdelay), f8dot3(estoffset), f8dot3(jd)))
+ PeerSummary.prettyinterval(poll_sec), reach,
+ fini(estdelay), fini(estoffset), fini(jd)))
line += "\n"
# for debugging both case
# if srcadr != None and srchost != None:
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/compare/bef535252d1386b5f1adc60d3550ef7348d87af3...fae7938abd5cee75dcde482bb46a5bf82ff1563c
--
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/compare/bef535252d1386b5f1adc60d3550ef7348d87af3...fae7938abd5cee75dcde482bb46a5bf82ff1563c
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20210213/adbae970/attachment-0001.htm>
More information about the vc
mailing list