Login

Another Memcache Status View

Author:
cmheisel
Posted:
February 14, 2008
Language:
Python
Version:
.96
Tags:
memcache
Score:
1 (after 1 ratings)

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

  1. Memcache Status by gfranxman 8 years, 3 months ago
  2. Property Attributes in Memcache by ori 3 years, 7 months ago
  3. Cache Backend using memcached including prefix settings by mojemeno123 2 years, 11 months ago
  4. A simple client to get some info (NOT values...) from memcached by pterk 5 years, 11 months ago
  5. JSON instead of pickle for memcached by diverman 3 years, 4 months ago

Comments

Please login first before commenting.