[Git][NTPsec/ntpsec][master] 2 commits: ntpviz: more code simplification around values.

Gary E. Miller gitlab at mg.gitlab.com
Wed Jan 11 03:59:01 UTC 2017


Gary E. Miller pushed to branch master at NTPsec / ntpsec


Commits:
e66c5c9b by Gary E. Miller at 2017-01-10T19:32:27-08:00
ntpviz: more code simplification around values.

Also annotate SHM(x).

- - - - -
495a671c by Gary E. Miller at 2017-01-10T19:58:06-08:00
ntpviz: calculate temps summaryies and add to csv file.

- - - - -


1 changed file:

- ntpclients/ntpviz


Changes:

=====================================
ntpclients/ntpviz
=====================================
--- a/ntpclients/ntpviz
+++ b/ntpclients/ntpviz
@@ -55,6 +55,13 @@ ntpviz: can't find the Python argparse module
     sys.exit(1)
 
 
+# table to translate refclock names
+refclock_name = {'127.127.28.0': 'SHM(0)',
+                 '127.127.28.1': 'SHM(1)',
+                 '127.127.28.2': 'SHM(2)',
+                 '127.127.28.3': 'SHM(3)'}
+
+
 # Gack, python before 3.2 has no defined tzinfo for utc...
 # define our own
 class UTC(datetime.tzinfo):
@@ -144,6 +151,8 @@ class VizStats(ntp.statfiles.NTPStats):
     percs = {}          # dictionary of percentages
     title = ''          # title
     unit = 's'          # display units: s, ppm, etc.
+    skip_summary = False
+    clipped = False
     multiplier = 1
 
     # observe RFC 4180, end lines with CRLF
@@ -264,6 +273,7 @@ class VizStats(ntp.statfiles.NTPStats):
 
         self.stats_html = """\
 <br>
+%(title)s:<br>
 <table style="margin-left:20px;border-spacing: 10px 0;">
   <tr style="text-align:left;font-weight:bold;">
     <td colspan=8> Percentiles......</td>
@@ -507,20 +517,24 @@ file.</p>
         # compute frequency offset
         stats_f = VizStats(values_f, "Local Clock Frequency Offset", freq=1)
 
-        stats = []
+        stats = [stats_f]
+        stats_html = ''
         plot_data_t = ''
         for key in tempslist:
             # speed up by only sending gnuplot the data it will actually use
             # fields: time, temp
             (p, v) = self.plot_slice(tempsmap[key], 3)
             plot_data_t += p
+            s = VizStats(v, key, units='°C')
+            stats_html += s.stats_html
+            stats.append(s)
 
         # out = stats.percs
         out = {}
         out["min_y2"] = stats_f.percs["min_y"]
         out["max_y2"] = stats_f.percs["max_y"]
         out["unit_f"] = stats_f.percs["unit"]
-        out["unit"] = 'C'
+        out["unit"] = '°C'
         out["multiplier_f"] = stats_f.percs["multiplier"]
         out["sitename"] = self.sitename
         out['size'] = args.png_size
@@ -562,13 +576,10 @@ file, and field 3 from the temp log .</p>
 
 """
 
-        ret = {}
-        # ret['html'] = stats.stats_html + stats_f.stats_html + exp
-        ret['html'] = stats_f.stats_html + exp
-        ret['stats'] = [stats, stats_f]
-        ret['stats'] = [stats_f]
-        ret['title'] = "Local Frequency/Temp"
-        ret['plot'] = plot_template + plot_data + plot_data_t
+        ret = {'html': stats_f.stats_html + stats_html + exp,
+               'plot': plot_template + plot_data + plot_data_t,
+               'stats': stats,
+               'title': "Local Frequency/Temp"}
         return ret
 
     def local_temps_gnuplot(self):
@@ -927,41 +938,27 @@ at 0s.</p>
 <p>RMS Jitter is field 8 in the peerstats log file.</p>
 """
 
-            # grab and sort the values, no need for the timestamp, etc.
-            values = [float(line[fld]) for line in peerdict[ip]]
-
-            stats = VizStats(values, title)
-
             if len(namelist[0]) and peerlist[0] != namelist[0]:
                 # append hostname, if we have it
                 # after stats to keep summary short
                 title += " (%s)" % namelist[0]
 
-            percentages = " %(p50)s title '50th percentile', " % stats.percs
-
-            exp = stats.stats_html + exp
-
         else:
             # many peers
             title += "s"
-            # grab and sort the values, no need for the timestamp, etc.
-            values = [float(line[fld]) for line in self.peerstats]
 
-            stats = VizStats(values, title)
-
-            exp = stats.stats_html
             if "offset" == type:
                 title = "Peer Offsets"
-                exp += """\
-<p>This shows the offset of all refclocks, peers and servers in
-%(unit)s.  This can be useful to see if offset changes are happening in
+                exp = """\
+<p>This shows the offset of all refclocks, peers and servers.
+This can be useful to see if offset changes are happening in
 a single clock or all clocks together.</p>
 
 <p>Clock Offset is field 5 in the peerstats log file.</p>
-""" % stats.percs
+"""
             else:
                 title = "Peer Jitters"
-                exp += """\
+                exp = """\
 <p>This shows the RMS Jitter of all refclocks, peers and servers.
 Jitter is the current estimated dispersion; the variation in offset
 between samples.</p>
@@ -972,6 +969,10 @@ at 0s.</p>
 <p>RMS Jitter is field 8 in the peerstats log file.</p>
 """
 
+        if len(peerlist) == 1:
+            if peerlist[0] in refclock_name:
+                title += ' ' + refclock_name[peerlist[0]]
+
         plot_data = ""
         for ip in ip_todo:
             # 20% speed up by only sending gnuplot the data it will
@@ -985,6 +986,14 @@ at 0s.</p>
                 (p, v1) = self.plot_slice(peerdict[ip], fld)
                 plot_data += p
 
+        stats = VizStats(v1, title)
+        if len(peerlist) == 1:
+            percentages = " %(p50)s title '50th percentile', " % stats.percs
+        else:
+            # skip stats on peers/offsets plots
+            stats.skip_summary = True
+            stats.stats_html = ''
+
         out = stats.percs
         out['sitename'] = self.sitename
         out['title'] = title
@@ -1023,8 +1032,10 @@ plot \
             # strip the trailing ", \n"
             plot_template = plot_template[:-4] + "\n"
 
-        ret = {'html': exp, 'stats': [stats], 'title': title}
-        ret['plot'] = plot_template + plot_data
+        ret = {'html': stats.stats_html + exp,
+               'stats': [stats],
+               'title': title,
+               'plot': plot_template + plot_data}
         return ret
 
     def peer_offsets_gnuplot(self, peerlist=None):
@@ -1747,6 +1758,8 @@ ntpviz</a>, part of the <a href="https://www.ntpsec.org/">NTPsec project</a>
             if [] == stat:
                 continue
             for sta in stat:
+                if sta.skip_summary:
+                    continue
                 index_buffer += str(sta.table)
                 csvs.append(sta.csv)
         # RFC 4180 specifies the mime-type of a csv



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/4e6b34e89cd2d5faaa3b9d8bd33e1112c12d8a85...495a671c3a4df2e080a0e32c24caaacf7a2e1f57
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170111/915ad69e/attachment.html>


More information about the vc mailing list