Get server cache statistics
From Zarafa wiki
(Difference between revisions)
| Line 18: | Line 18: | ||
<pre> | <pre> | ||
#!/usr/bin/python -u | #!/usr/bin/python -u | ||
| + | # | ||
| + | |||
| + | # Use no parameter to show cache hits vs. requests | ||
| + | # Use -a to show all stats + values | ||
import sys | import sys | ||
| Line 23: | Line 27: | ||
from MAPI.Defs import * | from MAPI.Defs import * | ||
from MAPI.Util import * | from MAPI.Util import * | ||
| + | |||
| + | try: | ||
| + | cmd_param = sys.argv[1] | ||
| + | except: | ||
| + | cmd_param = "" | ||
| + | pass | ||
def getStats(store): | def getStats(store): | ||
| Line 74: | Line 84: | ||
if not cstat.has_key(name): cstat[name] = {} | if not cstat.has_key(name): cstat[name] = {} | ||
cstat[name]['requests'] = int(stats[n]['value']) | cstat[name]['requests'] = int(stats[n]['value']) | ||
| + | if cmd_param == "-a": | ||
| + | print '%20s %30s' % (n, stats[n]['value']) | ||
| + | |||
| + | if cmd_param == "-a": | ||
| + | sys.exit(0) | ||
for name in cstat: | for name in cstat: | ||
Revision as of 15:29, 24 January 2012
This script will generate a userfriendly overview of the cache statistics of Zarafa, so you can directly see the cache usage in percentage.
uquota ( 0/ 0) (N/A)
index1 ( 339/ 357) (94%)
obj ( 754/ 799) (94%)
abinfo ( 274/ 277) (98%)
userid ( 283/ 344) (82%)
quota ( 0/ 0) (N/A)
server ( 0/ 0) (N/A)
cell ( 942/ 1567) (60%)
index2 ( 599/ 643) (93%)
extern ( 15/ 16) (93%)
acl ( 0/ 0) (N/A)
store ( 677/ 715) (94%)
#!/usr/bin/python -u
#
# Use no parameter to show cache hits vs. requests
# Use -a to show all stats + values
import sys
from MAPI import *
from MAPI.Defs import *
from MAPI.Util import *
try:
cmd_param = sys.argv[1]
except:
cmd_param = ""
pass
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 cmd_param == "-a":
print '%20s %30s' % (n, stats[n]['value'])
if cmd_param == "-a":
sys.exit(0)
for name in cstat:
if(cstat[name]['requests']):
percentage = '%d%%' % (cstat[name]['hits'] * 100 / cstat[name]['requests'])
else:
percentage = 'N/A'
print '%10s (%10d/%10d) (%3s)' % (name, cstat[name]['hits'], cstat[name]['requests'], percentage)