[Git][NTPsec/ntpsec][master] ntpviz: First steps towards comparative multiplotting.

Eric S. Raymond gitlab at mg.gitlab.com
Mon Aug 22 23:59:46 UTC 2016


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


Commits:
7c021b4b by Eric S. Raymond at 2016-08-22T19:58:57-04:00
ntpviz: First steps towards comparative multiplotting.

- - - - -


2 changed files:

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


Changes:

=====================================
docs/includes/ntpviz-body.txt
=====================================
--- a/docs/includes/ntpviz-body.txt
+++ b/docs/includes/ntpviz-body.txt
@@ -17,16 +17,19 @@
 == DESCRIPTION ==
 
 This utility analyzes files in an NTP log directory and generates
-statistical plots from them.  It can report either PNG images or
-the GNUPLOT programs to generate them to standard output.  In its
-default mode it generates an HTML directory containing all plots
-and an index page.
+statistical plots from them.  It can report either PNG images or the
+GNUPLOT programs to generate them to standard output.  In its default
+mode it generates an HTML directory containing an index page and
+either (a) all plots, for a single statfiles directory, or (b) a
+subset of comparative plots for multiple directories.
 
-The most basic option is -d, which specifies a logfile directory to
-examine; the default is /var/log/ntpstats.
+The most basic option is -d, which specifies one or more logfile
+directories to examine; the default is a single directory,
+/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 -n option allows you to set the sitename shown in the plot title,
+and is effective only for the single-directory case. The default is
+the basename of the log directory.
 
 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 either
@@ -104,7 +107,7 @@ output directory.  Neither file need be present, and both files may
 contain aribtrary HTML.
 
 The first file is named 'header'.  The contents of that file will be
-added almost at the top of the body on the generated index.
+added almost at the top of the body on the generated index page.
 
 This is the place to put links to other web pages, or headline notes.
 
@@ -124,7 +127,8 @@ font package installed.
 
 == AUTHORS ==
 
-Eric S. Raymond  and Daniel Drown. The GNUPLOT in this package is
-largely based on templates in Daniel Drown's 'chrony-graph' project.
+Eric S. Raymond, Gary E. Miller, and Daniel Drown. The GNUPLOT in this
+package is largely based on templates in Daniel Drown's 'chrony-graph'
+project.
 
 // end


=====================================
ntpstats/ntpviz
=====================================
--- a/ntpstats/ntpviz
+++ b/ntpstats/ntpviz
@@ -45,6 +45,18 @@ def gnuplot(template, outfile=None):
     proc.stdin.close()
     return proc.wait()
 
+def plotwrap(imagename, image, outfile):
+    "Generate an image and index section for a GNUPLOT section."
+    gnuplot(image, os.path.join(outdir, imagename + ".png"))
+    div_name = imagename.replace('-', ' ')
+    div = '''\
+<div>
+  <h3>%s</h3>
+  <img src='%s.png' alt='%s plot'>
+</div>
+''' % (div_name, imagename.replace(':', '%3A'), div_name)
+    outfile.write(div)
+
 class NTPViz(NTPStats):
     "Class for visualizing statistics from a single server."
     Common = """\
@@ -306,7 +318,7 @@ if __name__ == '__main__':
     show_peer_offsets = show_peer_jitters = None
     show_peer_rtt = None
     outdir = "ntpgraphs"
-    debug_level = 0
+    debug = 0
     nice = 0
     for (switch, val) in options:
         if switch == "-d":
@@ -461,18 +473,18 @@ if __name__ == '__main__':
                 sys.stdout.write(plot)
             raise SystemExit(0)
 
-        # Fall through to HTML code generation
-        if not os.path.isdir(outdir):
-            try:
-                os.mkdir(outdir)
-            except SystemError:
-                sys.stderr.write("ntpviz: ERROR: %s can't be created.\n" \
-                     % outdir)
-                raise SystemExit(1)
-        with open(os.path.join(outdir, "ntpsec-logo.png"), "w") as wp:
-            wp.write(binascii.a2b_base64(ntpsec_logo))
-
-        index_header = '''\
+    # Fall through to HTML code generation
+    if not os.path.isdir(outdir):
+        try:
+            os.mkdir(outdir)
+        except SystemError:
+            sys.stderr.write("ntpviz: ERROR: %s can't be created.\n" \
+                 % outdir)
+            raise SystemExit(1)
+    with open(os.path.join(outdir, "ntpsec-logo.png"), "w") as wp:
+        wp.write(binascii.a2b_base64(ntpsec_logo))
+
+    index_header = '''\
 <!DOCTYPE html>
 <html lang="en">
 <head>
@@ -488,11 +500,11 @@ if __name__ == '__main__':
 <div>
 <h1 style="margin-bottom:10px;">NTP Stats</h1>
 '''
-        index_header += 'Last Update: %s UTC <br>' %  start_time.strftime("%c")
-        index_header += 'Period: %s days <br></div> ' %  period_days
-        index_header += '<div style="clear:both;"></div>'
+    index_header += 'Last Update: %s UTC <br>' %  start_time.strftime("%c")
+    index_header += 'Period: %s days <br></div> ' %  period_days
+    index_header += '<div style="clear:both;"></div>'
 
-        index_trailer = '''\
+    index_trailer = '''\
 <br>
 <br>
 <br>
@@ -502,39 +514,41 @@ ntpviz</a>, part of the <a href="https://www.ntpsec.org/">NTPsec project</a>
 </body>
 </html>
 '''
-        imagepairs = [
-            ("local-offset", stats.local_offset_gnuplot()),
-            ("local-error", stats.local_error_gnuplot()),
-            ("local-jitter", stats.local_offset_jitter_gnuplot()),
-            ("local-stability", stats.local_offset_stability_gnuplot()),
-            ("local-offset-histogram", stats.local_offset_histogram_gnuplot()),
-            ("peer-offsets", stats.peer_offsets_gnuplot()),
-            ("local-cpu-temp", stats.local_cpu_temp_gnuplot()),
-            ]
-        for key in stats.peersplit().keys():
-            imagepairs.append(("peer-offset-" + key,
-                           stats.peer_offsets_gnuplot([key])))
-        imagepairs.append(("peer-jitters",
-                           stats.peer_jitters_gnuplot()))
-        for key in stats.peersplit().keys():
-            plot = stats.peer_jitters_gnuplot([key])
-            if len( plot ):
-                imagepairs.append(("peer-jitter-" + key, plot))
-
-        for (imagename, image) in imagepairs:
-            gnuplot(image, os.path.join(outdir, imagename + ".png"))
-            with open(os.path.join(outdir, "index.html"), "w") as ifile:
-                ifile.write(index_header)
-                # if header file, add it to index.html
-                header = os.path.join(outdir, "header")
-                if os.path.isfile(header):
-                    try:
-                        header_file = open( header, 'r')
-                        header_txt = header_file.read()
-                        ifile.write('<br>\n' + header_txt + '\n')
-                    except IOError:
-                        pass
-                # now the graphs
+    with open(os.path.join(outdir, "index.html"), "w") as ifile:
+        # if header file, add it to index.html
+        header = os.path.join(outdir, "header")
+        if os.path.isfile(header):
+            try:
+                header_file = open( header, 'r')
+                header_txt = header_file.read()
+                ifile.write('<br>\n' + header_txt + '\n')
+            except IOError:
+                pass
+
+        if len(statlist) > 1:
+            sys.stderr.write("Comparative multiplotting not yet implemented.\n")
+        else:
+            imagepairs = [
+                ("local-offset", stats.local_offset_gnuplot()),
+                ("local-error", stats.local_error_gnuplot()),
+                ("local-jitter", stats.local_offset_jitter_gnuplot()),
+                ("local-stability", stats.local_offset_stability_gnuplot()),
+                ("local-offset-histogram", stats.local_offset_histogram_gnuplot()),
+                ("peer-offsets", stats.peer_offsets_gnuplot()),
+                ("local-cpu-temp", stats.local_cpu_temp_gnuplot()),
+                ]
+            for key in stats.peersplit().keys():
+                imagepairs.append(("peer-offset-" + key,
+                               stats.peer_offsets_gnuplot([key])))
+            imagepairs.append(("peer-jitters",
+                               stats.peer_jitters_gnuplot()))
+            for key in stats.peersplit().keys():
+                plot = stats.peer_jitters_gnuplot([key])
+                if len( plot ):
+                    imagepairs.append(("peer-jitter-" + key, plot))
+
+            for (imagename, image) in imagepairs:
+                gnuplot(image, os.path.join(outdir, imagename + ".png"))
                 for (imagename, _) in imagepairs:
                     div_name = imagename.replace('-', ' ')
                     div = '''\
@@ -544,18 +558,19 @@ ntpviz</a>, part of the <a href="https://www.ntpsec.org/">NTPsec project</a>
 </div>
 ''' % (div_name, imagename.replace(':', '%3A'), div_name)
                     ifile.write( div )
-                # if footer file, add it to index.html
-                footer = os.path.join(outdir, "footer")
-                if os.path.isfile(footer):
-                    try:
-                        footer_file = open( footer, 'r')
-                        footer_txt = footer_file.read()
-                        ifile.write('<br>\n' + footer_txt + '\n')
-                    except IOError:
-                        pass
-                # and finish the file
-                ifile.write(index_trailer)
-                ifile.close()
+
+        # if footer file, add it to index.html
+        footer = os.path.join(outdir, "footer")
+        if os.path.isfile(footer):
+            try:
+                footer_file = open( footer, 'r')
+                footer_txt = footer_file.read()
+                ifile.write('<br>\n' + footer_txt + '\n')
+            except IOError:
+                pass
+        # and finish the file
+        ifile.write(index_trailer)
+        ifile.close()
 
 
 if 9 == debug_level:



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


More information about the vc mailing list