This was inspired by this memcache status snippet
However, this version uses the quasi-internal cache._cache.get_status(), and it compiles a list of stats for each server that you specify in your CACHE_BACKEND setting.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30  | from django import http
from django.shortcuts import render_to_response
from django.conf import settings
from django.core.cache import cache
from django.template import RequestContext
import datetime, re
def cache_status(request):
    try:
        import memcache
    except ImportError:
        raise http.Http404
    if not (request.user.is_authenticated() and request.user.is_staff):
        raise http.Http404
    
    stats = cache._cache.get_stats()   #Beware, using _cache, may change
    
    per_server_stats = []
    for server, server_stats in stats:
        server_stats['server_name'] = server
        try:
            server_stats['hit_rate'] = 100 * float(server_stats['get_hits']) / float(server_stats['cmd_get'])
        except Exception, e:
            server_stats['hit_rate'] = str(e)
        per_server_stats.append(server_stats)
    
    context = dict(per_server_stats=per_server_stats, time=datetime.datetime.now())
    return render_to_response('memcachestatus/index.html', context, context_instance=RequestContext(request))
 | 
More like this
- Add Toggle Switch Widget to Django Forms by OgliariNatan 1 month, 4 weeks ago
 - get_object_or_none by azwdevops 5 months, 2 weeks ago
 - Mask sensitive data from logger by agusmakmun 7 months, 2 weeks ago
 - Template tag - list punctuation for a list of items by shapiromatron 1 year, 9 months ago
 - JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 1 year, 9 months ago
 
Comments
Please login first before commenting.