summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2019-03-13 06:47:02 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2019-03-13 06:47:02 (GMT)
commitd5e93609b79881233fb6a43957d8d276373d2d67 (patch)
treea69fbe8d5a88589a8210bd06891777da21977bbe
parent2da1526175da8692febb2a4fba5deab357d75a0f (diff)
downloadmisc-fred-d5e93609b79881233fb6a43957d8d276373d2d67.zip
misc-fred-d5e93609b79881233fb6a43957d8d276373d2d67.tar.gz
misc-fred-d5e93609b79881233fb6a43957d8d276373d2d67.tar.bz2
munin: add script to get count of forms for a single tenant
-rwxr-xr-xmunin/publik_count_60
1 files changed, 60 insertions, 0 deletions
diff --git a/munin/publik_count_ b/munin/publik_count_
new file mode 100755
index 0000000..a95a9ba
--- /dev/null
+++ b/munin/publik_count_
@@ -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