diff options
Diffstat (limited to 'scripts/analyze-rcynic-history.py')
-rw-r--r-- | scripts/analyze-rcynic-history.py | 61 |
1 files changed, 34 insertions, 27 deletions
diff --git a/scripts/analyze-rcynic-history.py b/scripts/analyze-rcynic-history.py index fdf850cc..f45a0578 100644 --- a/scripts/analyze-rcynic-history.py +++ b/scripts/analyze-rcynic-history.py @@ -19,10 +19,9 @@ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. """ -plot_all_hosts = False -plot_to_one = False -plot_to_many = True -write_rcynic_xml = True +plot_all_hosts = False + +window_hours = 72 import mailbox import sys @@ -80,8 +79,8 @@ class Host(object): del self.uris @property - def failure_rate_percentage(self): - return float(self.dead_connections * 100) / float(self.connection_count) + def failed(self): + return 1 if self.dead_connections else 0 @property def seconds_per_object(self): @@ -119,7 +118,7 @@ class Host(object): Format("object_count", "Objects", "d", "Objects In Repository (Distinct URIs Per Session)"), Format("objects_per_connection", "Objects/Connection", ".3f", "Objects In Repository / Connections To Repository"), Format("seconds_per_object", "Seconds/Object", ".3f", "Seconds To Transfer / Object (Average Per Session)"), - Format("failure_rate_percentage", "Failure Rate", ".3f%%", "Connection Failures / Connections (Per Session)"), + Format("failure_rate_running", "Failure Rate", ".3f%%", "Sessions With Failed Connections Within Last %d Hours" % window_hours), Format("average_connection_time", "Average Connection", ".3f", "Seconds / Connection (Average Per Session)"), Format("hostname", "Hostname", "s")) @@ -137,6 +136,8 @@ class Session(dict): def __init__(self, session_id, msg_key): self.session_id = session_id self.msg_key = msg_key + self.date = parse_utc(session_id) + self.calculated_failure_history = False @property def hostnames(self): @@ -159,6 +160,18 @@ class Session(dict): for h in self.itervalues(): h.finalize() + def calculate_failure_history(self, sessions): + start = self.date - datetime.timedelta(hours = window_hours) + sessions = tuple(s for s in sessions if s.date <= self.date and s.date > start) + for hostname, h in self.iteritems(): + i = n = 0 + for s in sessions: + if hostname in s: + i += s[hostname].failed + n += 1 + h.failure_rate_running = float(100 * i) / n + self.calculated_failure_history = True + def plotter(f, hostnames, field, logscale = False): plotlines = sorted(session.get_plot_row(field, hostnames) for session in sessions) title = Host.format_dict[field].title @@ -177,7 +190,9 @@ def plotter(f, hostnames, field, logscale = False): set xdata time set timefmt '%Y-%m-%dT%H:%M:%SZ' #set format x '%m/%d' - set format x '%b%d' + #set format x '%b%d' + #set format x '%Y-%m-%d' + set format x '%Y-%m' #set title '""" + title + """' set ylabel '""" + ylabel + """' plot""" + ",".join(" '-' using 1:2 with linespoints pointinterval 500 title '%s'" % h for h in hostnames) + "\n") @@ -186,7 +201,7 @@ def plotter(f, hostnames, field, logscale = False): f.write("%s %s\n" % (plotline[0], plotline[i].rstrip("%"))) f.write("e\n") -def plot_many(hostnames, fields): +def plot_hosts(hostnames, fields): for field in fields: for logscale in (False, True): gnuplot = subprocess.Popen(("gnuplot",), stdin = subprocess.PIPE) @@ -196,17 +211,6 @@ def plot_many(hostnames, fields): gnuplot.stdin.close() gnuplot.wait() -def plot_one(hostnames, fields): - gnuplot = subprocess.Popen(("gnuplot",), stdin = subprocess.PIPE) - gnuplot.stdin.write("set terminal pdf\n") - gnuplot.stdin.write("set output 'analyze-rcynic-history.pdf'\n") - for field in fields: - if field != "hostname": - plotter(gnuplot.stdin, hostnames, field, logscale = False) - plotter(gnuplot.stdin, hostnames, field, logscale = True) - gnuplot.stdin.close() - gnuplot.wait() - mb = mailbox.Maildir("/u/sra/rpki/rcynic-xml", factory = None, create = False) if sys.platform == "darwin": # Sigh @@ -219,7 +223,7 @@ sessions = [] latest = None for i, key in enumerate(mb.iterkeys(), 1): - sys.stderr.write("\r%s %d/%d..." % ("|\\-/"[i & 3], i, len(mb))) + sys.stderr.write("\r%s Reading %d/%d..." % ("|\\-/"[i & 3], i, len(mb))) if key in shelf: session = shelf[key] @@ -246,6 +250,13 @@ sys.stderr.write("\n") shelf.sync() +for i, session in enumerate(sessions, 1): + sys.stderr.write("\r%s Failure history %d/%d...%s..." % ("|\\-/"[i & 3], i, len(sessions), session.session_id)) + if not getattr(session, "calculated_failure_history", False): + session.calculate_failure_history(sessions) + shelf[session.msg_key] = session +sys.stderr.write("\n") + if plot_all_hosts: hostnames = sorted(reduce(lambda x, y: x | y, (s.hostnames for s in sessions), @@ -256,13 +267,9 @@ else: "rpki.afrinic.net", "rpki-pilot.arin.net", "arin.rpki.net", "rgnet.rpki.net") -fields = [fmt.attr for fmt in Host.format if fmt.attr != "hostname"] -if plot_to_one: - plot_one(hostnames, fields) -if plot_to_many: - plot_many(hostnames, fields) +plot_hosts(hostnames, [fmt.attr for fmt in Host.format if fmt.attr != "hostname"]) -if write_rcynic_xml and latest is not None: +if latest is not None: f = open("rcynic.xml", "wb") f.write(mb[latest.msg_key].get_payload()) f.close() |