[Git][NTPsec/ntpsec][master] 2 commits: Print what we can get if server doesn't know about a variable
Hal Murray
gitlab at mg.gitlab.com
Wed Dec 28 01:53:51 UTC 2016
Hal Murray pushed to branch master at NTPsec / ntpsec
Commits:
65b01117 by Hal Murray at 2016-12-27T17:53:32-08:00
Print what we can get if server doesn't know about a variable
- - - - -
e6b218ed by Hal Murray at 2016-12-27T17:53:32-08:00
Tweak mru printout
add MJD on direct mode
3 decimal digits if avgint < 1.0
calculate avgint as delta/(count-1)
- - - - -
2 changed files:
- ntpclients/ntpq
- pylib/util.py
Changes:
=====================================
ntpclients/ntpq
=====================================
--- a/ntpclients/ntpq
+++ b/ntpclients/ntpq
@@ -446,8 +446,22 @@ usage: timeout [ msec ]
try:
queried = self.session.readvar(associd, [v[0] for v in variables])
except ntp.packet.ControlException as e:
- self.warn(e.message + "\n")
- return
+ if ntp.control.CERR_UNKNOWNVAR == e.errorcode:
+ items = []
+ for var in [v[0] for v in variables]:
+ try:
+ queried = self.session.readvar(associd, [var])
+ for (name, value) in queried.items():
+ items.append((name, value))
+ except ntp.packet.ControlException as e:
+ if ntp.control.CERR_UNKNOWNVAR == e.errorcode:
+ items.append((var, "???"))
+ continue
+ raise e
+ queried = ntp.util.OrderedDict(items)
+ else:
+ self.warn(e.message + "\n")
+ return
except IOError as e:
print(e.strerror)
return
=====================================
pylib/util.py
=====================================
--- a/pylib/util.py
+++ b/pylib/util.py
@@ -487,21 +487,27 @@ class MRUSummary:
last = ntp.ntpc.lfptofloat(entry.last)
if self.now:
lstint = int(self.now - last + 0.5)
+ stats = "%7d" % lstint
else:
# direct mode doesn't have a reference time
- # use seconds this day
+ MJD_1970 = 40587 # MJD for 1 Jan 1970, Unix epoch
days = int(last) / 86400
seconds = last - days*86400
lstint = int(seconds)
+ stats = "%5d %5d" % (days + MJD_1970, lstint)
first = ntp.ntpc.lfptofloat(entry.first)
active = float(last - first)
- favgint = active / entry.ct # FIXME should be ct-1
+ if entry.ct == 1:
+ favgint = 0
+ else:
+ favgint = active / (entry.ct-1)
avgint = int(favgint + 0.5)
- stats = "%7d" % lstint
- if 5 < avgint or 1 == entry.ct:
+ if 5.0 < favgint or 1 == entry.ct:
stats += " %6d" % avgint
- else:
+ elif 1.0 <= favgint:
stats += " %6.2f" % favgint
+ else:
+ stats += " %6.3f" % favgint
if entry.rs & ntp.magic.RES_KOD:
rscode = 'K'
elif entry.rs & ntp.magic.RES_LIMITED:
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/5c18650ea39879cab6c426c843557a6d47de466f...e6b218ed16dbac3c5c980538502931322f18ae82
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20161228/c5f5a661/attachment.html>
More information about the vc
mailing list