summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2021-05-13 12:27:41 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2021-05-13 12:27:41 (GMT)
commit36122853fa73bad2f8fb5f3eb0464e0dea84a769 (patch)
treefe1eaac566bf224d64856769f9445be515d4aa87
parent7ecbc33621a038796ef8eb0f9cae7475ffd844d7 (diff)
downloadmisc-fred-36122853fa73bad2f8fb5f3eb0464e0dea84a769.zip
misc-fred-36122853fa73bad2f8fb5f3eb0464e0dea84a769.tar.gz
misc-fred-36122853fa73bad2f8fb5f3eb0464e0dea84a769.tar.bz2
munin: add script to get count of recently submitted forms
-rwxr-xr-xmunin/publik_recent_count67
1 files changed, 67 insertions, 0 deletions
diff --git a/munin/publik_recent_count b/munin/publik_recent_count
new file mode 100755
index 0000000..dc9974c
--- /dev/null
+++ b/munin/publik_recent_count
@@ -0,0 +1,67 @@
+#! /usr/bin/env python
+#%# family=auto
+#%# capabilities=autoconf
+
+import cPickle
+import datetime
+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)
+
+if len(sys.argv) == 2 and sys.argv[1] == 'config':
+ print '''graph_title Count of recently submitted forms
+graph_category entrouvert
+count_5m.label Count (5 minutes)
+count_1h.label Count (1 hour)
+count_1d.label Count (k) (1 day)
+'''
+ sys.exit(0)
+
+total_5m = 0
+total_1h = 0
+total_1d = 0
+
+time_5m = datetime.datetime.now() - datetime.timedelta(minutes=5)
+time_1h = datetime.datetime.now() - datetime.timedelta(hours=1)
+time_1d = datetime.datetime.now() - datetime.timedelta(days=1)
+
+for tenant in os.listdir(base_dir):
+ if tenant in ('collectstatic', 'scripts', 'skeletons', 'spooler'):
+ 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)
+ try:
+ for var, time in zip(('total_5m', 'total_1h', 'total_1d'), (time_5m, time_1h, time_1d)):
+ cur = pgconn.cursor()
+ cur.execute('''SELECT COUNT(*) from wcs_all_forms WHERE status != 'draft' AND receipt_time > %(time)s''', {'time': time})
+ locals()[var] += cur.fetchone()[0]
+ except psycopg2.ProgrammingError:
+ pass
+ pgconn.close()
+
+print 'count_5m.value', total_5m
+print 'count_1h.value', total_1h
+print 'count_1d.value', int(total_1d / 1000)