munin: add script to count number of forms
This commit is contained in:
parent
7f98c56239
commit
38b5ce52f1
|
@ -0,0 +1,45 @@
|
|||
#! /usr/bin/env python
|
||||
|
||||
import cPickle
|
||||
import os
|
||||
import psycopg2
|
||||
import sys
|
||||
|
||||
if len(sys.argv) == 2 and sys.argv[1] == 'autoconf':
|
||||
print 'yes'
|
||||
sys.exit(0)
|
||||
|
||||
if len(sys.argv) == 2 and sys.argv[1] == 'config':
|
||||
print '''graph_title Count of submitted forms
|
||||
graph_category entrouvert
|
||||
count.label Count
|
||||
'''
|
||||
sys.exit(0)
|
||||
|
||||
total = 0
|
||||
base_dir = '/var/lib/machines/wcs.rbx.prod.entrouvert.org/var/lib/wcs/'
|
||||
for tenant in os.listdir(base_dir):
|
||||
if tenant in ('collectstatic', 'scripts', 'skeletons'):
|
||||
continue
|
||||
if tenant.endswith('.invalid'):
|
||||
continue
|
||||
if not os.path.isdir(os.path.join(base_dir, tenant)):
|
||||
continue
|
||||
cfg = cPickle.load(open(os.path.join(base_dir, tenant, 'config.pck')))
|
||||
if not 'postgresql' in cfg:
|
||||
continue
|
||||
psql_cfg = {}
|
||||
for k, v in cfg['postgresql'].items():
|
||||
if v and isinstance(v, basestring):
|
||||
psql_cfg[k] = v
|
||||
pgconn = psycopg2.connect(**psql_cfg)
|
||||
cur = pgconn.cursor()
|
||||
try:
|
||||
cur.execute('''SELECT COUNT(*) from wcs_all_forms WHERE status != 'draft' ''')
|
||||
except psycopg2.ProgrammingError:
|
||||
pass
|
||||
else:
|
||||
total += cur.fetchone()[0]
|
||||
pgconn.close()
|
||||
|
||||
print 'count.value', total
|
Loading…
Reference in New Issue