Add support for multiple zeus boxes

This commit is contained in:
Wil Clouser 2010-08-10 10:40:50 -07:00
Родитель b3e06b9300
Коммит 5f8dac08d8
5 изменённых файлов: 64 добавлений и 25 удалений

Просмотреть файл

@ -51,7 +51,7 @@
</div>
<div class="notification-box {{ status(status_summary.redis) }}">
<h2>Redis Info</h2>
<h2>[Redis] Redis Info</h2>
{% with info, error = redis_results %}
{% if info %}
<ul>
@ -66,4 +66,21 @@
{% endwith %}
</div>
<div class="notification-box {{ status(status_summary.hera) }}">
<h2>[Zeus] Connection Tests (Hera)</h2>
<ul>
{% for result in hera_results %}
<li>{{ result.location }}:
{% if result.result %}
Success
{% else %}
<strong>Failed</strong>
{% endif %}
</li>
{% else %}
<li>Hera isn't configured!</li>
{% endfor %}
</ul>
</div>
{% endblock main_content %}

Просмотреть файл

@ -2,6 +2,7 @@ import os
import random
import socket
import urllib2
from urlparse import urlparse
from django import http
from django.conf import settings
@ -14,8 +15,7 @@ import commonware.log
import jingo
import phpserialize as php
from amo.urlresolvers import reverse
from api.views import render_xml
from hera.contrib.django_utils import get_hera
from stats.models import Contribution, ContributionError, SubscriptionEvent
from . import log
@ -84,11 +84,22 @@ def monitor(request):
status_summary['filepaths'] = filepath_status
# Check Redis
redis_results = [None, 'REDIS_BACKEND is not set']
if getattr(settings, 'REDIS_BACKEND', False):
redis_results = check_redis()
status_summary['redis'] = bool(redis_results[0])
# Check Hera
hera_results = []
status_summary['hera'] = True
for i in settings.HERA:
r = {'location': urlparse(i['LOCATION'])[1],
'result': bool(get_hera(i))}
hera_results.append(r)
if not hera_results[-1]['result']:
status_summary['hera'] = False
# If anything broke, send HTTP 500
if not all(status_summary):
status = 500
@ -97,6 +108,7 @@ def monitor(request):
{'memcache_results': memcache_results,
'filepath_results': filepath_results,
'redis_results': redis_results,
'hera_results': hera_results,
'status_summary': status_summary},
status=status)

Просмотреть файл

@ -46,19 +46,22 @@
</div>
<div class="secondary">
<h3>Stats</h3>
{% if stats %}
{% if stats.num_lookups > 0 %}
{# Can't jinja2 detect a division by zero and just do something intelligent? #}
{% set hit_percentage = stats.num_hits / stats.num_lookups %}
{% else %}
{% set hit_percentage = 0 %}
{% endif %}
<ul>
<li>Using {{ stats.bytes_used|filesizeformat }} ({{ stats.percent_used }}% of total space) for {{ stats.entries }} objects.</li>
<li>We've had {{ stats.num_hits }} hits out of {{ stats.num_lookups }} lookups ({{ hit_percentage }}%).</li>
</ul>
{% else %}
<p>Not Available</p>
{% endif %}
{% for i in boxes %}
<h4>{{ i.location }}</h4>
{% if i.stats %}
{% if i.stats.num_lookups > 0 %}
{# Can't jinja2 detect a division by zero and just do something intelligent? #}
{% set hit_percentage = i.stats.num_hits / i.stats.num_lookups %}
{% else %}
{% set hit_percentage = 0 %}
{% endif %}
<ul>
<li>Using {{ i.stats.bytes_used|filesizeformat }} ({{ i.stats.percent_used }}% of total space) for {{ i.stats.entries }} objects.</li>
<li>We've had {{ i.stats.num_hits }} hits out of {{ i.stats.num_lookups }} lookups ({{ hit_percentage }}%).</li>
</ul>
{% else %}
<p>Not Available</p>
{% endif %}
{% endfor %}
</div>
{% endblock %}

Просмотреть файл

@ -1,3 +1,5 @@
from urlparse import urlparse
from django import http
# I'm so glad we named a function in here settings...
from django.conf import settings as site_settings
@ -65,14 +67,19 @@ def flagged(request):
def hera(request):
form = FlushForm(initial={'flushprefix': site_settings.SITE_URL})
hera = get_hera()
boxes = []
configured = False # Default to not showing the form.
for i in site_settings.HERA:
hera = get_hera(i)
r = {'location': urlparse(i['LOCATION'])[1], 'stats': False}
if hera:
r['stats'] = hera.getGlobalCacheInfo()
configured = True
boxes.append(r)
if not hera:
if not configured:
messages.error(request, "Hera is not (or mis-)configured.")
form = None
stats = None
else:
stats = hera.getGlobalCacheInfo()
if request.method == 'POST' and hera:
form = FlushForm(request.POST)
@ -87,7 +94,7 @@ def hera(request):
messages.success(request, msg)
return jingo.render(request, 'zadmin/hera.html',
{'form': form, 'stats': stats})
{'form': form, 'boxes': boxes})
@admin.site.admin_view

Просмотреть файл

@ -472,10 +472,10 @@ CUSTOM_DUMPS = {
}
## Hera (http://github.com/clouserw/hera)
HERA = {'USERNAME': '',
HERA = [{'USERNAME': '',
'PASSWORD': '',
'LOCATION': '',
}
}]
# Logging
LOG_LEVEL = logging.DEBUG