def write_remailer_stats(name, addy, vitals): # Create a filename for the remailer details, open it and write a title and timestamp. noat = addy.replace("@", ".") filename = "%s/%s.%s.txt" % (config.reportdir, name, noat) statfile = open("%s" % (filename,), "w") statfile.write("Pinger statistics for the %(rem_name)s remailer (%(rem_addy)s)\n" % vitals) statfile.write("Last update: %s (UTC)\n" % timefunc.utcnow()) statfile.write("\nPingers\n") statfile.write(" Known: %d\t" % db.count_total_pingers()) statfile.write("Alive: %d\t" % vitals["rem_count_all"]) statfile.write("In-Scope: %d\t" % vitals["rem_active_count"]) # Out of scope pings are total Alive pings minus In-Scope Pings oos = vitals["rem_count_all"] - vitals["rem_active_count"] statfile.write("Out-of-Scope: %d\n" % oos) statfile.write("\nUptime\n") statfile.write(" Lowest: %3.2f%%\t\t" % (vitals["rem_uptime_min"] / 10.00)) statfile.write("Average: %3.2f%%\n" % (float(vitals["rem_uptime_avg"]) / 10.00)) statfile.write(" Highest: %3.2f%%\t" % (vitals["rem_uptime_max"] / 10.00)) statfile.write("StdDev: %3.2f%%\n" % (float(vitals["rem_uptime_stddev"]) / 10.00)) statfile.write("\nLatency\n") statfile.write(" Lowest: %d:%02d\t\t" % timefunc.hours_mins(vitals["rem_latency_min"])) statfile.write("Average: %d:%02d\n" % timefunc.hours_mins(vitals["rem_latency_avg"])) statfile.write(" Highest: %d:%02d\t\t" % timefunc.hours_mins(vitals["rem_latency_max"])) statfile.write("StdDev: %d:%02d\n" % timefunc.hours_mins(vitals["rem_latency_stddev"])) statfile.write("\nIn-scope pings\n") for row in db.remailer_active_pings(vitals): entry = db_process(row) statfile.write(entry) statfile.write("\n\nOut of scope pings\n") for row in db.remailer_ignored_pings(vitals): entry = db_process(row) statfile.write(entry) statfile.write("\n\nDead pings\n") for row in db.remailer_inactive_pings(vitals): entry = db_process(row) statfile.write(entry) statfile.close()
def uptimes(): ago = timefunc.hours_ago(config.active_age) ahead = timefunc.hours_ahead(config.active_future) uptimes = avg_uptime() #logger.debug("Writing Uptime HTML file %s", config.uptime_report_name) filename = "%s/%s" % (config.reportdir, config.uptime_report_name) uptimefile = open(filename, 'w') uptimefile.write("""<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Style-Type" content="text/css2" /> <meta name="keywords" content="Mixmaster,Remailer,Banana,Bananasplit"> <title>Bananasplit Website - Failing Remailers</title> <link rel="StyleSheet" href="stats.css" type="text/css"> </head> <body> <h1>Remailer Uptimes</h1> <p>This report provides an overview of the average uptime for each remailer based on the results from all currently responding pingers. Consider that this report doesn't define a scope for acceptable ping results; all are considered good. This means a single pinger can skew the average.</p> <table border="0" bgcolor="#000000"> <tr bgcolor="#F08080"> <th>Remailer Name</th> <th>Average Uptime</th> <th>Average Latency</th> <th>Pingers Reporting</th></tr>\n""") rotate_color = 0 for uptime in uptimes: # Rotate background colours for rows if rotate_color: bgcolor = "#ADD8E6" else: bgcolor = "#E0FFFF" rotate_color = not rotate_color name = uptime[0] up = uptime[1] count = uptime[3] lathrs,latmin = timefunc.hours_mins(uptime[2]) uptimefile.write('<tr bgcolor="%s">' % bgcolor) uptimefile.write('<th class="tableleft">%s</th>' % name) uptimefile.write('<td>%3.2f</td>' % up) uptimefile.write('<td>%d:%02d</td>' % (lathrs, latmin)) uptimefile.write('<td>%d</td></tr>\n' % (count, )) uptimefile.write('</table>\n') uptimefile.write('<br>Last update: %s (UTC)<br>\n' % timefunc.utcnow()) uptimefile.write('<br><a href="index.html">Index</a>\n') uptimefile.write('</body></html>') uptimefile.close()