munin: add script to get count of forms for a single tenant
This commit is contained in:
parent
2da1526175
commit
d5e93609b7
|
@ -0,0 +1,60 @@
|
|||
#! /usr/bin/env python
|
||||
|
||||
import cPickle
|
||||
import os
|
||||
import psycopg2
|
||||
import sys
|
||||
|
||||
base_dir = None
|
||||
for dirname in os.listdir('/var/lib/machines/'):
|
||||
if os.path.exists(os.path.join('/var/lib/machines/', dirname, 'var/lib/wcs')):
|
||||
base_dir = os.path.join('/var/lib/machines/', dirname, 'var/lib/wcs')
|
||||
break
|
||||
|
||||
if len(sys.argv) == 2 and sys.argv[1] == 'autoconf':
|
||||
if base_dir:
|
||||
print 'yes'
|
||||
else:
|
||||
print 'no'
|
||||
sys.exit(0)
|
||||
|
||||
tenant = os.path.basename(sys.argv[0]).replace('publik_count_', '')
|
||||
|
||||
if len(sys.argv) == 2 and sys.argv[1] == 'config':
|
||||
print '''graph_title Count of forms for %s
|
||||
graph_category entrouvert
|
||||
total_count.label Total
|
||||
total_user_count.label Front
|
||||
total_logged_user_count.label Front by logged user
|
||||
''' % tenant
|
||||
sys.exit(0)
|
||||
|
||||
for tenant_dir in os.listdir(base_dir):
|
||||
if tenant_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
|
||||
if psql_cfg.get('host') == 'prod.saas.entrouvert.org.clusters.entrouvert.org':
|
||||
# override for routing
|
||||
psql_cfg['host'] = '10.0.0.10'
|
||||
pgconn = psycopg2.connect(**psql_cfg)
|
||||
cur = pgconn.cursor()
|
||||
cur.execute('''SELECT COUNT(*) from wcs_all_forms WHERE status != 'draft' ''')
|
||||
total_count = cur.fetchone()[0]
|
||||
|
||||
cur.execute('''SELECT COUNT(*) from wcs_all_forms WHERE status != 'draft' AND backoffice_submission = FALSE''')
|
||||
total_user_count = cur.fetchone()[0]
|
||||
|
||||
cur.execute('''SELECT COUNT(*) from wcs_all_forms WHERE status != 'draft' AND backoffice_submission = FALSE AND user_id is not NULL''')
|
||||
total_logged_user_count = cur.fetchone()[0]
|
||||
|
||||
print 'total_count.value', total_count
|
||||
print 'total_user_count.value', total_user_count
|
||||
print 'total_logged_user_count.value', total_logged_user_count
|
||||
pgconn.close()
|
||||
break
|
Loading…
Reference in New Issue