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
- Template tag - list punctuation for a list of items by shapiromatron 11 months, 1 week ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months, 2 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 6 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 7 months ago
- Help text hyperlinks by sa2812 1 year, 7 months ago
Comments
Please login first before commenting.