Get server cache statistics

From Zarafa wiki

Revision as of 16:51, 16 January 2013 by Paulb (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This script will generate a user friendly overview of the cache statistics of Zarafa, so you can directly see the cache hit ratio and the cache usage in percentage. The hit ratio should be as high as possible. The combination of low hit ratio and high cache usage indicates a too small cache size.

This script is tested on 7.x.

root@xxxx:/usr/local/bin# zarafa-cachestat
Zarafa Cache Statistics
  Server start time: Thu Jan 10 21:09:18 2013
  Current time     : Wed Jan 16 17:42:07 2013

     Cache                Hit ratio                  Mem usage ratio
    uquota (           0/           0) (N/A)   (          64/     1048576) ( 0%)
       obj (   909462877/   910265045) (99%)   (    10065216/    10485760) (95%)
    abinfo (    17175285/    17175560) (99%)   (       29248/    26214400) ( 0%)
    userid (    25964914/    25987021) (99%)   (       10960/     1048576) ( 1%)
     quota (      195140/      260191) (74%)   (         352/     1048576) ( 0%)
    server (      431803/      433484) (99%)   (         288/     1048576) ( 0%)
      cell (  1761792387/  1812015150) (97%)   (   517106686/   536870912) (96%)
    index2 (   215740705/   230625673) (93%)   (    16626514/    16777216) (99%)
    extern (    11627581/    16040737) (72%)   (        8464/     1048576) ( 0%)
    index1 (   211822863/   218770977) (96%)   (    16147744/    16777216) (96%)
     store (   407886364/   490365215) (83%)   (     1042104/     1048576) (99%)
       acl (      998569/     1001342) (99%)   (       33844/     1048576) ( 3%)
#!/usr/bin/python -u

import sys
import datetime
from MAPI import *
from MAPI.Defs import *
from MAPI.Util import *

def getStats(store):
    systemtable = store.OpenProperty(PR_EC_STATSTABLE_SYSTEM, IID_IMAPITable, 0, 0)
    systemtable.SetColumns([PR_DISPLAY_NAME, PR_EC_STATS_SYSTEM_VALUE, PR_EC_STATS_SYSTEM_DESCRIPTION], TBL_BATCH)

    stats = {}
    while True:
        rows = systemtable.QueryRows(-1, 0)

        if len(rows) == 0: break

        for row in rows:
            stats[row[0].Value] = {}
            stats[row[0].Value]['value'] = row[1].Value
            stats[row[0].Value]['description'] = row[2].Value

    return stats

def diff(new, old):
    d = {}

    if not old:
        for n in new.keys():
            try:
                d[n] = int(new[n]['value'])
            except ValueError: pass

    else:
        for n in new.keys():
            try:
                d[n] = int(new[n]['value']) - int(old[n]['value'])
            except ValueError: pass

    return d

session = OpenECSession('SYSTEM', '', 'file:///var/run/zarafa')
store = GetDefaultStore(session)

stats = getStats(store)
cstat = {}
serverstarttime = ''

for n in stats.keys():
    if n == 'server_start_date':
        serverstarttime = stats[n]['value']

    if n.startswith('cache_'):
        if n.endswith('_hit'):
            name = n[6:-4]
            if not cstat.has_key(name): cstat[name] = {}
            cstat[name]['hits'] = int(stats[n]['value'])
        if n.endswith('_req'):
            name = n[6:-4]
            if not cstat.has_key(name): cstat[name] = {}
            cstat[name]['requests'] = int(stats[n]['value'])
        if n.endswith('_size'):
            name = n[6:-5]
            if not cstat.has_key(name): cstat[name] = {}
            cstat[name]['size'] = int(stats[n]['value'])
        if n.endswith('_maxsz'):
            name = n[6:-6]
            if not cstat.has_key(name): cstat[name] = {}
            cstat[name]['maxsz'] = int(stats[n]['value'])

print 'Zarafa Cache Statistics'
print '  Server start time: %s' % ( serverstarttime )
print '  Current time     : %s' % ( datetime.datetime.now().strftime('%c') )
print ''
print '%10s %24s         %24s' % ('Cache', 'Hit ratio', 'Mem usage ratio')

for name in cstat:
    if ('requests' not in cstat[name]):
        continue

    if(cstat[name]['requests']):
        percentage = '%d%%' % (cstat[name]['hits'] * 100 / cstat[name]['requests'])
    else:
        percentage = 'N/A'

    if ('maxsz' in cstat[name]):
        persize = '%d%%' % (cstat[name]['size'] * 100 / cstat[name]['maxsz'])
    else:
        persize = 'N/A'

    print '%10s (%12d/%12d) (%3s)   (%12d/%12d) (%3s)' % (name, cstat[name]['hits'], cstat[name]['requests'], percentage, cstat[name]['size'], cstat[name]['maxsz'], persize)
Personal tools