[Git][NTPsec/ntpsec][master] Add -e (endpoint) option to ntpviz.

Eric S. Raymond gitlab at mg.gitlab.com
Thu Aug 11 16:58:32 UTC 2016


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
f5b6a0ec by Eric S. Raymond at 2016-08-11T12:51:53-04:00
Add -e (endpoint) option to ntpviz.

- - - - -


3 changed files:

- docs/includes/ntpviz-body.txt
- ntpstats/ntpstats.py
- ntpstats/ntpviz


Changes:

=====================================
docs/includes/ntpviz-body.txt
=====================================
--- a/docs/includes/ntpviz-body.txt
+++ b/docs/includes/ntpviz-body.txt
@@ -5,7 +5,8 @@
 [[synop]]
 == SYNOPSIS ==
 [verse]
-{ntpviz} [-d statsdir] [-g] [-n name] [-p period] [-s starttime]
+{ntpviz} [-d statsdir] [-g] [-n name] [-p period]
+         [-s starttime] [-e endtime]
          [--local-offset | --local-jitter | --local-stability]
          [--peer-offsets hosts | --all-peer-offsets]
          [--peer-jitters hosts | --all-peer-jitters]
@@ -22,11 +23,13 @@ examine; the default is /var/log/ntpstats.
 The -n option allows you to set the sitename shown in the plot title.
 The default is the basename of the log directory.
 
-The -s and -p options allow you to set the time window to be reported
-on. With -s you set the start time as an ISO8601-style timestamp
-- yyyy-mmm-ddThh:mm:ss. With -p you set the default in days.  The default
-is for the period to be 7 days and the start time to be set so that adding
-the period just reaches the last logfile entry.
+The -s, -e and -p options allow you to set the time window to be
+reported on. With -s and -e you set the start and end times as
+ISO8601-style timestamps, - yyyy-mmm-ddThh:mm:ss. Alternatively you
+can specify either -s or -e (but not both) and use -p to set the
+default period in days.  The default is for the period to be 7 days,
+the end time to match the last logfile entry, and the start time to be
+set so that adding the period just reaches the last logfile entry.
 
 The plot options choose what graph is generated; invoke only one.  By
 default, the GNUPLOT for the graph is reported; with -g you get the


=====================================
ntpstats/ntpstats.py
=====================================
--- a/ntpstats/ntpstats.py
+++ b/ntpstats/ntpstats.py
@@ -277,10 +277,6 @@ def isotime(s):
     else:
         raise TypeError
 
-def iso_to_unix(tv):
-    "ISO timestamp in local time to Unix time."
-    return calendar.timelocal(time.strptime(tv, "%Y-%m-%dT%H:%M:%S"))
-
 def gnuplot(template):
     "Run a specified GNUPLOT program."
     proc = subprocess.Popen("gnuplot",


=====================================
ntpstats/ntpviz
=====================================
--- a/ntpstats/ntpviz
+++ b/ntpstats/ntpviz
@@ -2,7 +2,8 @@
 """\
 ntpviz - logfile visualizer for NTP log files
 
-Usage: ntpviz [-d statsdir] [-g] [-n name] [-p period] [-s starttime]
+Usage: ntpviz [-d statsdir] [-g] [-n name] [-p period]
+              [-s starttime]  [-e endtime]
               [--local-offset | --local-jitter | --local-stability]
               [--peer-offsets hosts | --all-peer-offsets]
               [--peer-jitters hosts | --all-peer-jitters]
@@ -17,7 +18,7 @@ from ntpstats import *
 
 if __name__ == '__main__':
     try:
-        (options, arguments) = getopt.getopt(sys.argv[1:], "d:ghn:p:s:", [
+        (options, arguments) = getopt.getopt(sys.argv[1:], "d:e:ghn:p:s:", [
             "local-offset", "local-jitter", "local-stability",
             "all-peer-offsets", "peer-offsets=",
             "all-peer-jitters", "peer-jitters=",
@@ -29,7 +30,7 @@ if __name__ == '__main__':
     period = 7	# days
     sitename = None
     statsdir = "/var/log/ntpstats"
-    starttime = None
+    endtime = starttime = None
     generate = False
     show_local_offset = show_local_jitter = show_local_stability = False
     show_peer_offsets = show_peer_jitters = None
@@ -37,6 +38,8 @@ if __name__ == '__main__':
     for (switch, val) in options:
         if switch == "-d":
             statsdir = val
+        elif switch == "-e":
+            endtime = isotime(val)
         elif switch == "-g":
             generate = True
         elif switch == "-h":
@@ -47,7 +50,7 @@ if __name__ == '__main__':
         elif switch == "-p":
             period = int(val)	# Denominated in days
         elif switch == "-s":
-            starttime = iso_to_unix(val)
+            starttime = isotime(val)
         elif switch == "--local-offset":
             show_local_offset = True
         elif switch == "--local-jitter":
@@ -67,12 +70,17 @@ if __name__ == '__main__':
     period *= 24 * 60 * 60
     stats = NTPStats(sitename=sitename, statsdir=statsdir)
     # Default to one week before the latest date
-    if starttime is None:
-        starttime = int(stats.rangemax()) - period 
+    if endtime is None and starttime == None:
+        endtime = int(stats.rangemax())
+        starttime = endtime - period
+    elif starttime is None and endtime is not None:
+        starttime = endtime - period
+    elif starttime is not None and endtime is None:
+        endtime = starttime + period
     if stats.sitename is None:
         stats.sitename = os.path.basename(statsdir)
     if starttime:
-        stats.clip(starttime, starttime + period)
+        stats.clip(starttime, endtime)
 
     for fontpath in ("/usr/share/fonts/liberation",
                      "/usr/share/fonts/liberation-fonts",



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/f5b6a0ecbcd5d334927d5deedd54107fd07ebd97
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20160811/ffc54596/attachment.html>


More information about the vc mailing list