[Git][NTPsec/ntpsec][master] 6 commits: ntpmon: fix line overflow of version line
Gary E. Miller
gitlab at mg.gitlab.com
Wed Aug 9 01:51:15 UTC 2017
Gary E. Miller pushed to branch master at NTPsec / ntpsec
Commits:
03ad5cf7 by Gary E. Miller at 2017-08-08T17:14:05-07:00
ntpmon: fix line overflow of version line
- - - - -
558fe43f by Gary E. Miller at 2017-08-08T17:23:29-07:00
ntpmon: make w tottle MRUSumary too
- - - - -
7e7e09d7 by Gary E. Miller at 2017-08-08T17:40:44-07:00
Add ntp.util.stringfile() to pretty print filt*
filtdelay, fitloffset, fitldisp now line up nicely in ntmpon.
- - - - -
c68f0dbc by Gary E. Miller at 2017-08-08T17:51:36-07:00
remove commas from ntpmon detail display.
- - - - -
2819c6a7 by Gary E. Miller at 2017-08-08T18:22:56-07:00
ntpmon detail, remove more commas.
- - - - -
61f88834 by Gary E. Miller at 2017-08-08T18:45:47-07:00
ntpmon: more detail view cleanup.
- - - - -
2 changed files:
- ntpclients/ntpmon
- pylib/util.py
Changes:
=====================================
ntpclients/ntpmon
=====================================
--- a/ntpclients/ntpmon
+++ b/ntpclients/ntpmon
@@ -27,9 +27,9 @@ Any keystroke causes a poll and update. Keystroke commands:
from __future__ import print_function, division
+import getopt
import sys
import time
-import getopt
try:
import ntp.packet
@@ -74,7 +74,7 @@ def statline(_peerlist, _mrulist, nyquist):
# We don't use stdversion here because the presence of a date is confusing
leader = sysvars['version'][0]
if span.entries:
- trailer = "Last update: %s (%s)" \
+ trailer = "Updated: %s (%s)" \
% (iso8601(span.entries[0].last),
ntp.util.PeerSummary.prettyinterval(nyquist))
else:
@@ -91,6 +91,7 @@ def peer_detail(variables, showunits=False):
vcopy = {}
vcopyraw = {}
vcopy.update(variables)
+ width = ntp.util.termsize().width - 2
# Need to separate the casted from the raw
for key in vcopy.keys():
vcopyraw[key] = vcopy[key][1]
@@ -122,21 +123,27 @@ def peer_detail(variables, showunits=False):
vcopy['filtoffset'] = ntp.util.stringfiltcooker(vcopyraw['filtoffset'])
vcopy['filtdisp'] = ntp.util.stringfiltcooker(vcopyraw['filtdisp'])
else:
- vcopy['filtdelay'] = vcopy['filtdelay'].replace(' ', '\t')
- vcopy['filtoffset'] = vcopy['filtoffset'].replace(' ', '\t')
- vcopy['filtdisp'] = vcopy['filtdisp'].replace(' ', '\t')
+ vcopy['filtdelay'] = ntp.util.stringfilt(vcopyraw['filtdelay'])
+ vcopy['filtoffset'] = ntp.util.stringfilt(vcopyraw['filtoffset'])
+ vcopy['filtdisp'] = ntp.util.stringfilt(vcopyraw['filtdisp'])
# annotate IPv6, to stand out from :port
if ':' in vcopy['srcadr']:
vcopy['srcadr'] = '[' + vcopy['srcadr'] + ']'
if ':' in vcopy['dstadr']:
vcopy['dstadr'] = '[' + vcopy['dstadr'] + ']'
+ vcopy['adr'] = "dstadr=%(dstadr)s:%(dstport)s " \
+ "srcadr=%(srcadr)s:%(srcport)d" % vcopy
+ if len(vcopy['adr']) > width:
+ # too long, break the line
+ vcopy['adr'] = vcopy['adr'].replace(" ", "\n")
+
peerfmt = """\
-dstadr=%(dstadr)s:%(dstport)s srcadr=%(srcadr)s:%(srcport)d
+%(adr)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)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
+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
@@ -320,7 +327,7 @@ if __name__ == '__main__':
opcode=ntp.control.CTL_OP_READCLOCK,
raw=True)
strconvert = ntp.util.cook(clockvars,
- showunits)
+ showunits, " ")
stdscr.addstr(strconvert.encode('UTF-8'))
except ntp.packet.ControlException as e:
pass
@@ -367,7 +374,9 @@ if __name__ == '__main__':
showunits = not showunits
peer_report.showunits = showunits
elif key == 'w':
- peer_report.wideremote = not peer_report.wideremote
+ wideremote = not wideremote
+ peer_report.wideremote = wideremote
+ mru_report.wideremote = wideremote
elif key == " ":
if peer_report.displaymode == 'peers':
peer_report.displaymode = 'apeers'
@@ -395,7 +404,7 @@ if __name__ == '__main__':
session.debug -= 1
peer_report.debug = session.debug
mru_report.debug = session.debug
- elif key in ['?','h']:
+ elif key in ['?', 'h']:
helpmode = True
except curses.error:
pass
=====================================
pylib/util.py
=====================================
--- a/pylib/util.py
+++ b/pylib/util.py
@@ -111,6 +111,18 @@ def portsplit(hostname):
return (hostname, portsuffix)
+def stringfilt(data):
+ "pretty print string of space separated numbers"
+ parts = data.split()
+
+ cooked = []
+ for part in parts:
+ fitted = fitinfield(part, 7)
+ cooked.append(fitted)
+ rendered = " ".join(cooked)
+ return rendered
+
+
def stringfiltcooker(data):
"Cooks a filt* string of space separated numbers, expects milliseconds"
parts = data.split()
@@ -452,7 +464,7 @@ def f8dot3(f):
elif f > -100000.0:
fmt = "%8.1f" # -xxxxx.x
- return fmt % f
+ return fmt % f
# A hack to avoid repeatedly hammering on DNS when ntpmon runs.
@@ -587,7 +599,7 @@ class PeerStatusWord:
% self.__dict__)
-def cook(variables, showunits=False):
+def cook(variables, showunits=False, sep=", "):
"Cooked-mode variable display."
width = ntp.util.termsize().width - 2
text = ""
@@ -662,7 +674,9 @@ def cook(variables, showunits=False):
item += repr(value)
else:
item += repr(value)
- item += ", "
+ # add field separator
+ item += sep
+ # add newline so we don not overflow screen
lastcount = 0
for c in text:
if c == '\n':
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/97c4e3ef8ebb1cc581000edafe7bcba9d4302063...61f888343bc0ac37d460be8f6cadcc6d9dc47fec
---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/97c4e3ef8ebb1cc581000edafe7bcba9d4302063...61f888343bc0ac37d460be8f6cadcc6d9dc47fec
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/20170809/99b28450/attachment.html>
More information about the vc
mailing list