Esempio n. 1
0
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()
Esempio n. 2
0
def main():
    init_logging()  # Before anything else, initialise logging.
    logger.info("Beginning process cycle at %s (UTC)", timefunc.utcnow())
    socket.setdefaulttimeout(config.timeout)
    global stat_re, addy_re, chain_re
    stat_re = re.compile("(\w{1,12})\s+([0-9A-H?]{12}\s.*)")
    addy_re = re.compile('\$remailer\{"([0-9a-z]{1,12})"\}\s\=\s"\<(.*)\>\s')
    chain_re = re.compile("\((\S{1,12})\s(\S{1,12})\)")

    # Are we running in testmode?  Testmode implies the script was executed
    # without a --live argument.
    testmode = live_or_test(sys.argv)

    # If not in testmode, fetch url's and process them
    if not testmode:
        pingers = db.pinger_names()
        for row in pingers:
            url = url_fetch(row[1])
            if url:
                url_process(row[0], url)
        # Fetch pubring.mix files and write them to the DB
        getkeystats()
    else:
        logger.debug("Running in testmode, url's will not be retreived")

    # We need to do some periodic housekeeping.  It's not very process
    # intensive so might as well do it every time we run.
    db.housekeeping(timefunc.hours_ago(config.dead_after_hours))

    # For a pinger to be considered active, it must appear in tables mlist2
    # and pingers.  This basically means, don't create empty pinger columns
    # in the index file.
    active_pingers = db.active_pinger_names()

    # A boolean value to rotate row colours within the index
    rotate_color = 0

    # The main loop.  This creates individual remailer text files and
    # indexing data based on database values.
    for name, addy in db.distinct_rem_names():
        logger.debug("Generating statsistics for remailer %s", name)

        # remailer_vitals is a dictionary of standard deviation and average
        # values for a specific remailer.
        remailer_vitals = gen_remailer_vitals(name, addy)

        # remailer_active_pings: Based on the vitals generated above, we now
        # extract stats lines for pingers considered active.  The up_hist
        # part is used by the fail_recover routine.
        remailer_active_pings = db.remailer_active_pings(remailer_vitals)
        # If a remailers is perceived to be dead, timestamp it in the
        # genealogy table.  Likewise, if it's not dead, unstamp it.
        fail_recover(name, addy, remailer_active_pings)

        # Write the remailer text file that contains pinger stats and averages
        logger.debug("Writing stats file for %s %s", name, addy)
        write_remailer_stats(name, addy, remailer_vitals)

        # Rotate the colour used in index generation.
        rotate_color = not rotate_color

    db.gene_find_new()
    index()
    genealogy()
    uptimes()
    chainstats()
    writekeystats()
    logger.info("Processing cycle completed at %s (UTC)", timefunc.utcnow())
Esempio n. 3
0
def failed(report_name):
    filename = "%s/%s" % (config.reportdir, config.failed_report_name)
    htmlfile = open(filename, 'w')

# Write standard html header section
    htmlfile.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>Failing Remailers</h1>
Remailer stats are normally biased away from the current day.  This is because
different latencies would skew results due to outstanding pings.  However the
current day does provide a rapid insight into remailers that are currently
experiencing problems.<br>
<p>The following table lists remailers that are <u>currently</u> averaging less
than %d%% return on pings. Please consider that this could be due to very high
latency rather than actual remailer failure.</p>
<p><i>Note: Bunker is not actually failing.  It's a Middleman remailer with no
current stats which means it cannot random hop pings back to the pinger.</i></P>
<table border="0" bgcolor="#000000">
<tr bgcolor="#F08080">
<th>Remailer Name</th><th>Ping Responses</th>
</tr>""" % (config.failpoint * 10))

    rotate_color = 0

    for name, addy in db.distinct_rem_names():
        remailer_vitals = gen_remailer_vitals(name, addy)
        logger.debug("Checking remailer %s %s", name, addy)
        addy_noat = addy.replace('@',".")
        full_name = "%s.%s" % (name, addy_noat)

        active_pings = db.remailer_active_pings(remailer_vitals)
        if len(active_pings) == 0:
            logger.info("We have no active pings for %s %s", name, addy)
            continue

        remailer_vitals['uptime'] = up_today(active_pings)

        if remailer_vitals['uptime'] < config.failpoint:
            logger.info("Remailer %s %s is failed.", name, addy)
            # Rotate background colours for rows
            if rotate_color:
                bgcolor = "#ADD8E6"
            else:
                bgcolor = "#E0FFFF"
            rotate_color = not rotate_color
            
            htmlfile.write('<tr bgcolor="%s"><th class="tableleft"><a href="%s.txt" title="%s">%s</a></th>' % (bgcolor, full_name, addy, name))
            htmlfile.write('<td>%d%%</td></tr>\n' % (remailer_vitals['uptime'] * 10))

#        if remailer_vitals('uptime'] > config.goodpoint:
#            # Stats are greater than 50%, so delete any entries for this
#            # remailer from the failed table.
#            logger.debug("%s is healthy, deleting any DB entries it might have", name)

    htmlfile.write('</table>\n')

    htmlfile.write('<br>Last update: %s (UTC)<br>\n' % utcnow())
    htmlfile.write('<br><a href="index.html">Return to Index</a>')

    htmlfile.write('</body></html>')