[Git][NTPsec/ntpsec][master] Refacforing step - move graphing code from ntpstats.py into ntpviz.

Eric S. Raymond gitlab at mg.gitlab.com
Thu Aug 11 18:54:11 UTC 2016


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


Commits:
57f78944 by Eric S. Raymond at 2016-08-11T14:53:16-04:00
Refacforing step - move graphing code from ntpstats.py into ntpviz.

- - - - -


2 changed files:

- ntpstats/ntpstats.py
- ntpstats/ntpviz


Changes:

=====================================
ntpstats/ntpstats.py
=====================================
--- a/ntpstats/ntpstats.py
+++ b/ntpstats/ntpstats.py
@@ -68,7 +68,7 @@ class NTPStats:
                     m = ts
         return m
     def rangemin(self):
-        "Get the latest timestamp in the files"
+        "Get the earliest timestamp in the files"
         m = sys.float_info.max
         for field in  ("clockstats", "peerstats", "loopstats", "rawstats"):
             row = getattr(self, field)
@@ -115,145 +115,6 @@ class NTPStats:
             except socket.herror:
                 pass
         return key	# Someday, be smarter than this.
-    def local_clock_gnuplot(self):
-        "Generate GNUPLOT code graphing local clock loop statistics"
-        sitename = self.sitename
-        plot_template = """\
-set title "%(sitename)s: Local Clock Offsets"
-set terminal png size 900,600
-set xdata time
-set timefmt "@s"
-set grid
-set xlabel "Time"
-set format x "@d- at H:@M"
-set xtic rotate by -45 scale 0
-set ytics format "@1.2f us" nomirror textcolor rgb '#0060ad'
-set y2tics format "@2.3f ppm" nomirror textcolor rgb '#dd181f'
-set key bottom right box
-set style line 1 lc rgb '#0060ad' lt 1 lw 1 pt 7 ps 0   # --- blue
-set style line 2 lc rgb '#dd181f' lt 1 lw 1 pt 5 ps 0   # --- red
-set lmargin 12
-set rmargin 12
-plot \
- "-" using 1:($2*1000000) title "clock offset us" with linespoints ls 1, \
- "-" using 1:3 title "frequency offset ppm" with linespoints ls 2 axis x1y2
-""" % locals()
-        return plot_template.replace('@', '%') + self.dump("loopstats") + "e\n" + self.dump("loopstats")
-    def loopstats_gnuplot(self, fld, title, legend):
-        "Generate GNUPLOT code of a given loopstats field"
-        sitename   = self.sitename
-        ninetynine = self.percentile(fld, 95, self.loopstats) * 1000000
-        ninetyfive = self.percentile(fld, 99, self.loopstats) * 1000000
-        five       = self.percentile(fld,  5, self.loopstats) * 1000000
-        one        = self.percentile(fld,  1, self.loopstats) * 1000000
-        nf_m_f     = ninetyfive - five
-        nn_m_o     = ninetynine - one
-        plot_template = """\
-set title "%(sitename)s: %(title)s"
-set terminal png size 900,600
-set xdata time
-set timefmt "@s"
-set grid
-set xlabel "Time"
-set format x "@d- at H:@M"
-set xtic rotate by -45 scale 0
-set ytics format "@1.2f us" nomirror
-set key top right box
-set style line 1 lc rgb '#0060ad' lt 1 lw 1 pt 7 ps 0   # --- blue
-set style line 2 lc rgb '#dd181f' lt 1 lw 1 pt 5 ps 0   # --- red
-set label 1 gprintf("99@@ = %(ninetynine)s us",99) at graph 0.01,0.95 left front
-set label 2 gprintf("95@@ = %(ninetyfive)s us",95) at graph 0.01,0.9 left front
-set label 3 gprintf(" 5@@ = %(five)s us",5) at graph 0.01,0.85 left front
-set label 4 gprintf(" 1@@ = %(one)s us",1) at graph 0.01,0.8 left front
-set label 5 gprintf("95@@ - 5@@ = %(nf_m_f)s us",90) at graph 0.01,0.75 left front
-set label 6 gprintf("99@@ - 1@@ = %(nn_m_o) us",98) at graph 0.01,0.7 left front
-set lmargin 12
-set rmargin 12
-plot \
- "-" using 1:($%(fld)d*1000000) title "%(legend)s" with linespoints ls 1, \
- %(ninetynine)s title "99th percentile", \
- %(ninetyfive)s title "95th percentile", \
- %(five)s title "5th percentile", \
- %(one)s title "1st percentile"
-""" % locals()
-        return plot_template.replace('@', '%') + self.dump("loopstats")
-    def local_clock_jitter_gnuplot(self):
-        "Generate GNUPLOT code of local clock loop standard deviation"
-        return self.loopstats_gnuplot(4, "RMS Time jitter", "Jitter")
-    def local_clock_stability_gnuplot(self):
-        "Generate GNUPLOT code graphing local clock stability"
-        return self.loopstats_gnuplot(5, "RMS Frequency Jitter - ADEV aka wander", "Stability")
-    def peerstats_gnuplot(self, peerlist, fld, title):
-        "Plot a specified field from peerstats."
-        peerdict = self.peersplit()
-        if not peerlist:
-            peerlist = list(peerdict.keys())
-        peerlist.sort()	# For stability of output
-        if len(peerlist) == 1:
-            title += ": "+ peerlist[0]
-        else:
-            title += "s"
-        plot_template = """\
-set title "%s"
-set terminal png size 900,600
-set xdata time
-set timefmt "@s"
-set grid
-set xlabel "Time"
-set format x "@d- at H:@M"
-set xtic rotate by -45 scale 0
-set ylabel ""
-set ytics format "@1.0f us" nomirror
-set key top right box
-set lmargin 12
-set rmargin 12
-plot \\
-""" % title
-	plot_template = plot_template.replace("@", "%")
-        for key in peerlist:
-            plot_template += "'-' using 1:($%d*1000000) title '%s' with line, \\\n" % (fld, self.ip_label(key))
-        
-        plot_template = plot_template[:-4] + "\n"
-        for key in peerlist:
-            if key in peerdict:
-                plot_template += "\n".join(peerdict[key]) + "\ne\n"
-            else:
-                sys.stderr.write("No such peer as %s" % key)
-                raise SystemExit(1)
-        return plot_template[:-2]
-    def peer_offsets_gnuplot(self, peerlist):
-        return self.peerstats_gnuplot(peerlist, 4, "Peer clock offset")
-    def peer_jitters_gnuplot(self, peerlist):
-        return self.peerstats_gnuplot(peerlist, 7, "Peer clock jitter")
-    def peer_rtt_gnuplot(self, host):
-        "Plot offset with rtt bounds for specified host."
-        entries = self.peersplit()[host]
-        fifty = self.percentile(4,  50, entries) * 1000000
-        host = self.ip_label(host)
-        plot_template = """\
-set title "offset of %(host)s"
-set terminal png size 900,600
-set xdata time
-set timefmt "@s"
-set grid
-set xlabel "Time"
-set format x "@d- at H:@M"
-set xtic rotate by -45 scale 0
-set ylabel ""
-set ytics format "@1.0f us" nomirror
-set key top right box
-set lmargin 12
-set rmargin 12
-plot \
-'-' using 1:($4*1000000) title 'offset' with line, \
-'-' using 1:(($4+$5/2)*1000000) title 'offset+rtt/2' with line, \
-'-' using 1:(($4-$5/2)*1000000) title 'offset-rtt/2' with line, \
-%(fifty)s title '50th percentile'
-""" % locals()
-	plot_template = plot_template.replace("@", "%")
-        data = "\n".join(entries)
-        plot_template += data + "\ne\n"	+ data + "\ne\n" + data
-        return plot_template
 
 def isotime(s):
     "Convert timestamps in ISO8661 format to and from Unix time including optional fractional seconds."
@@ -264,7 +125,7 @@ def isotime(s):
         msec = s - date
         date = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(s))
         return date + "." + repr(msec)[3:]
-    elif isinstance(s, str) or isinstance(s, unicode)::
+    elif isinstance(s, str) or isinstance(s, unicode):
         if s[-1] == "Z":
             s = s[:-1]
         if "." in s:


=====================================
ntpstats/ntpviz
=====================================
--- a/ntpstats/ntpviz
+++ b/ntpstats/ntpviz
@@ -16,6 +16,152 @@ from __future__ import print_function, division
 import os, sys, getopt
 from ntpstats import *
 
+class NTPViz(NTPStats):
+    "Class for visualizing statistics from a sincle server."
+    def __init__(self, sitename, statsdir):
+        NTPStats.__init__(self, sitename, statsdir)
+    def local_clock_gnuplot(self):
+        "Generate GNUPLOT code graphing local clock loop statistics"
+        sitename = self.sitename
+        plot_template = """\
+set title "%(sitename)s: Local Clock Offsets"
+set terminal png size 900,600
+set xdata time
+set timefmt "@s"
+set grid
+set xlabel "Time"
+set format x "@d- at H:@M"
+set xtic rotate by -45 scale 0
+set ytics format "@1.2f us" nomirror textcolor rgb '#0060ad'
+set y2tics format "@2.3f ppm" nomirror textcolor rgb '#dd181f'
+set key bottom right box
+set style line 1 lc rgb '#0060ad' lt 1 lw 1 pt 7 ps 0   # --- blue
+set style line 2 lc rgb '#dd181f' lt 1 lw 1 pt 5 ps 0   # --- red
+set lmargin 12
+set rmargin 12
+plot \
+ "-" using 1:($2*1000000) title "clock offset us" with linespoints ls 1, \
+ "-" using 1:3 title "frequency offset ppm" with linespoints ls 2 axis x1y2
+""" % locals()
+        return plot_template.replace('@', '%') + self.dump("loopstats") + "e\n" + self.dump("loopstats")
+    def loopstats_gnuplot(self, fld, title, legend):
+        "Generate GNUPLOT code of a given loopstats field"
+        sitename   = self.sitename
+        ninetynine = self.percentile(fld, 95, self.loopstats) * 1000000
+        ninetyfive = self.percentile(fld, 99, self.loopstats) * 1000000
+        five       = self.percentile(fld,  5, self.loopstats) * 1000000
+        one        = self.percentile(fld,  1, self.loopstats) * 1000000
+        nf_m_f     = ninetyfive - five
+        nn_m_o     = ninetynine - one
+        plot_template = """\
+set title "%(sitename)s: %(title)s"
+set terminal png size 900,600
+set xdata time
+set timefmt "@s"
+set grid
+set xlabel "Time"
+set format x "@d- at H:@M"
+set xtic rotate by -45 scale 0
+set ytics format "@1.2f us" nomirror
+set key top right box
+set style line 1 lc rgb '#0060ad' lt 1 lw 1 pt 7 ps 0   # --- blue
+set style line 2 lc rgb '#dd181f' lt 1 lw 1 pt 5 ps 0   # --- red
+set label 1 gprintf("99@@ = %(ninetynine)s us",99) at graph 0.01,0.95 left front
+set label 2 gprintf("95@@ = %(ninetyfive)s us",95) at graph 0.01,0.9 left front
+set label 3 gprintf(" 5@@ = %(five)s us",5) at graph 0.01,0.85 left front
+set label 4 gprintf(" 1@@ = %(one)s us",1) at graph 0.01,0.8 left front
+set label 5 gprintf("95@@ - 5@@ = %(nf_m_f)s us",90) at graph 0.01,0.75 left front
+set label 6 gprintf("99@@ - 1@@ = %(nn_m_o) us",98) at graph 0.01,0.7 left front
+set lmargin 12
+set rmargin 12
+plot \
+ "-" using 1:($%(fld)d*1000000) title "%(legend)s" with linespoints ls 1, \
+ %(ninetynine)s title "99th percentile", \
+ %(ninetyfive)s title "95th percentile", \
+ %(five)s title "5th percentile", \
+ %(one)s title "1st percentile"
+""" % locals()
+        return plot_template.replace('@', '%') + self.dump("loopstats")
+    def local_clock_jitter_gnuplot(self):
+        "Generate GNUPLOT code of local clock loop standard deviation"
+        return self.loopstats_gnuplot(4, "RMS Time jitter", "Jitter")
+    def local_clock_stability_gnuplot(self):
+        "Generate GNUPLOT code graphing local clock stability"
+        return self.loopstats_gnuplot(5, "RMS Frequency Jitter - ADEV aka wander", "Stability")
+    def peerstats_gnuplot(self, peerlist, fld, title):
+        "Plot a specified field from peerstats."
+        peerdict = self.peersplit()
+        if not peerlist:
+            peerlist = list(peerdict.keys())
+        peerlist.sort()	# For stability of output
+        if len(peerlist) == 1:
+            title += ": "+ peerlist[0]
+        else:
+            title += "s"
+        plot_template = """\
+set title "%s"
+set terminal png size 900,600
+set xdata time
+set timefmt "@s"
+set grid
+set xlabel "Time"
+set format x "@d- at H:@M"
+set xtic rotate by -45 scale 0
+set ylabel ""
+set ytics format "@1.0f us" nomirror
+set key top right box
+set lmargin 12
+set rmargin 12
+plot \\
+""" % title
+	plot_template = plot_template.replace("@", "%")
+        for key in peerlist:
+            plot_template += "'-' using 1:($%d*1000000) title '%s' with line, \\\n" % (fld, self.ip_label(key))
+        
+        plot_template = plot_template[:-4] + "\n"
+        for key in peerlist:
+            if key in peerdict:
+                plot_template += "\n".join(peerdict[key]) + "\ne\n"
+            else:
+                sys.stderr.write("No such peer as %s" % key)
+                raise SystemExit(1)
+        return plot_template[:-2]
+    def peer_offsets_gnuplot(self, peerlist):
+        return self.peerstats_gnuplot(peerlist, 4, "Peer clock offset")
+    def peer_jitters_gnuplot(self, peerlist):
+        return self.peerstats_gnuplot(peerlist, 7, "Peer clock jitter")
+    def peer_rtt_gnuplot(self, host):
+        "Plot offset with rtt bounds for specified host."
+        entries = self.peersplit()[host]
+        fifty = self.percentile(4,  50, entries) * 1000000
+        host = self.ip_label(host)
+        plot_template = """\
+set title "offset of %(host)s"
+set terminal png size 900,600
+set xdata time
+set timefmt "@s"
+set grid
+set xlabel "Time"
+set format x "@d- at H:@M"
+set xtic rotate by -45 scale 0
+set ylabel ""
+set ytics format "@1.0f us" nomirror
+set key top right box
+set lmargin 12
+set rmargin 12
+plot \
+'-' using 1:($4*1000000) title 'offset' with line, \
+'-' using 1:(($4+$5/2)*1000000) title 'offset+rtt/2' with line, \
+'-' using 1:(($4-$5/2)*1000000) title 'offset-rtt/2' with line, \
+%(fifty)s title '50th percentile'
+""" % locals()
+	plot_template = plot_template.replace("@", "%")
+        data = "\n".join(entries)
+        plot_template += data + "\ne\n"	+ data + "\ne\n" + data
+        return plot_template
+
+
+
 if __name__ == '__main__':
     try:
         (options, arguments) = getopt.getopt(sys.argv[1:], "d:e:ghn:p:s:", [
@@ -68,7 +214,7 @@ if __name__ == '__main__':
         elif switch == "--peer-rtt":
             show_peer_rtt = val
     period *= 24 * 60 * 60
-    stats = NTPStats(sitename=sitename, statsdir=statsdir)
+    stats = NTPViz(sitename=sitename, statsdir=statsdir)
     # Default to one week before the latest date
     if endtime is None and starttime == None:
         endtime = int(stats.rangemax())



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


More information about the vc mailing list