diff options
-rw-r--r-- | mirrors/utils.py | 29 | ||||
-rw-r--r-- | mirrors/views.py | 17 | ||||
-rw-r--r-- | templates/mirrors/status.html | 11 |
3 files changed, 38 insertions, 19 deletions
diff --git a/mirrors/utils.py b/mirrors/utils.py index 69909dc..cdb705b 100644 --- a/mirrors/utils.py +++ b/mirrors/utils.py @@ -5,10 +5,11 @@ from .models import MirrorLog, MirrorProtocol, MirrorUrl import datetime +default_cutoff = datetime.timedelta(hours=24) @cache_function(300) -def get_mirror_statuses(): - cutoff_time = datetime.datetime.utcnow() - datetime.timedelta(hours=24) +def get_mirror_statuses(cutoff=default_cutoff): + cutoff_time = datetime.datetime.utcnow() - cutoff protocols = MirrorProtocol.objects.exclude(protocol__iexact='rsync') # I swear, this actually has decent performance... urls = MirrorUrl.objects.select_related('mirror', 'protocol').filter( @@ -41,11 +42,29 @@ def get_mirror_statuses(): else: url.delay = None url.score = None - return urls + + if urls: + last_check = max([u.last_check for u in urls]) + num_checks = max([u.check_count for u in urls]) + check_info = MirrorLog.objects.filter( + check_time__gte=cutoff_time).aggregate( + mn=Min('check_time'), mx=Max('check_time')) + check_frequency = (check_info['mx'] - check_info['mn']) / num_checks + else: + last_check = None + num_checks = 0 + check_frequency = None + + return { + 'last_check': last_check, + 'num_checks': num_checks, + 'check_frequency': check_frequency, + 'urls': urls, + } @cache_function(300) -def get_mirror_errors(): - cutoff_time = datetime.datetime.utcnow() - datetime.timedelta(hours=24) +def get_mirror_errors(cutoff=default_cutoff): + cutoff_time = datetime.datetime.utcnow() - cutoff errors = MirrorLog.objects.filter( is_success=False, check_time__gte=cutoff_time, url__mirror__active=True, url__mirror__public=True).values( diff --git a/mirrors/views.py b/mirrors/views.py index 71c896d..5c15789 100644 --- a/mirrors/views.py +++ b/mirrors/views.py @@ -55,7 +55,8 @@ def find_mirrors(request, countries=None, protocols=None, use_status=False): urls = qset.order_by('mirror__country', 'mirror__name', 'url') template = 'mirrors/mirrorlist.txt' else: - scores = dict([(u.id, u.score) for u in get_mirror_statuses()]) + status_info = get_mirror_statuses() + scores = dict([(u.id, u.score) for u in status_info['urls']]) urls = [] for u in qset: u.score = scores[u.id] @@ -72,13 +73,9 @@ def find_mirrors(request, countries=None, protocols=None, use_status=False): def status(request): bad_timedelta = datetime.timedelta(days=3) - urls = get_mirror_statuses() - - if urls: - last_check = max([u.last_check for u in urls]) - else: - last_check = None + status_info = get_mirror_statuses() + urls = status_info['urls'] good_urls = [] bad_urls = [] for url in urls: @@ -88,12 +85,12 @@ def status(request): else: good_urls.append(url) - context = { - 'last_check': last_check, + context = status_info.copy() + context.update({ 'good_urls': good_urls, 'bad_urls': bad_urls, 'error_logs': get_mirror_errors(), - } + }) return direct_to_template(request, 'mirrors/status.html', context) # vim: set ts=4 sw=4 et: diff --git a/templates/mirrors/status.html b/templates/mirrors/status.html index d89f2b4..03e4930 100644 --- a/templates/mirrors/status.html +++ b/templates/mirrors/status.html @@ -1,4 +1,5 @@ {% extends "base.html" %} +{% load mirror_status %} {% block title %}Arch Linux - Mirror Status{% endblock %} @@ -21,7 +22,7 @@ retrieved or contained data we didn't recognize, this column will show 'unknown'.</li> <li><em>μ Delay:</em> The calculated average mirroring delay; e.g. the - mean value of <code>last check − last sync</code> for each check of + mean value of <tt>last check − last sync</tt> for each check of this mirror URL.</li> <li><em>μ Duration:</em> The average (mean) time it took to connect and retrieve the <tt>lastsync</tt> file from the given URL. Note that this @@ -31,8 +32,8 @@ retrieval time. A high standard deviation can indicate an unstable or overloaded mirror.</li> <li><em>Mirror Score:</em> A very rough calculation for ranking - mirrors. It is currently calculated as <code>hours delay + average - duration + standard deviation</code>. Lower is better.</li> + mirrors. It is currently calculated as <tt>hours delay + average + duration + standard deviation</tt>. Lower is better.</li> </ul> <p>The final table on this page is an error log, which shows any errors that occurred while contacting mirrors. This only shows errors that @@ -43,7 +44,9 @@ <li><a href="#errorlog">Mirror Syncing Error Log</a></li> </ul> - <p>The last mirror check ran at {{ last_check|date:'Y-m-d H:i' }} UTC.</p> + <p>The last mirror check ran at {{ last_check|date:'Y-m-d H:i' }} UTC. + Checks have ran {{ num_checks }} times in the last 24 hours at an average + interval of {{ check_frequency|duration }} (hh:mm).</p> <a name="outofsync" id="outofsync"></a> <h3>Out of Sync Mirrors</h3> |