Get server cache statistics
From Zarafa wiki
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
Cache Hit ratio Usage ratio
uquota ( 0/ 0) (N/A) ( 0/ 1048576) ( 0%)
obj ( 29290291012/ 41036310149) (71%) ( 21270656/ 64000000) (33%)
abinfo ( 1859803/ 1862053) (99%) ( 259584/ 26214400) ( 0%)
userid ( 2413250/ 2415660) (99%) ( 97296/ 1048576) ( 9%)
quota ( 3390198/ 6874583) (49%) ( 12000/ 1048576) ( 1%)
server ( 35457/ 35472) (99%) ( 240/ 1048576) ( 0%)
cell ( 56918836480/ 57021245181) (99%) ( 5207464236/ 6000000000) (86%)
index2 ( 603792413/ 655902554) (92%) ( 74065218/ 128000000) (57%)
extern ( 4336198/ 4379517) (99%) ( 50800/ 1048576) ( 4%)
index1 ( 19811633172/ 19872619911) (99%) ( 54048624/ 128000000) (42%)
store ( 20534657987/ 39053980265) (52%) ( 394360/ 1048576) (37%)
acl ( 46719180/ 49069489) (95%) ( 364768/ 1048576) (34%)
#!/usr/bin/python -u
import sys
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 = {}
for n in stats.keys():
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 '%10s %24s %24s' % ('Cache', 'Hit ratio', '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)