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>
<div class="notification-box {{ status(status_summary.redis) }}"> <div class="notification-box {{ status(status_summary.redis) }}">
<h2>Redis Info</h2> <h2>[Redis] Redis Info</h2>
{% with info, error = redis_results %} {% with info, error = redis_results %}
{% if info %} {% if info %}
<ul> <ul>
@ -66,4 +66,21 @@
{% endwith %} {% endwith %}
</div> </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 %} {% endblock main_content %}

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

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

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

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

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

@ -1,3 +1,5 @@
from urlparse import urlparse
from django import http from django import http
# I'm so glad we named a function in here settings... # I'm so glad we named a function in here settings...
from django.conf import settings as site_settings from django.conf import settings as site_settings
@ -65,14 +67,19 @@ def flagged(request):
def hera(request): def hera(request):
form = FlushForm(initial={'flushprefix': site_settings.SITE_URL}) 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.") messages.error(request, "Hera is not (or mis-)configured.")
form = None form = None
stats = None
else:
stats = hera.getGlobalCacheInfo()
if request.method == 'POST' and hera: if request.method == 'POST' and hera:
form = FlushForm(request.POST) form = FlushForm(request.POST)
@ -87,7 +94,7 @@ def hera(request):
messages.success(request, msg) messages.success(request, msg)
return jingo.render(request, 'zadmin/hera.html', return jingo.render(request, 'zadmin/hera.html',
{'form': form, 'stats': stats}) {'form': form, 'boxes': boxes})
@admin.site.admin_view @admin.site.admin_view

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

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