munin: update publik_recent_count to use python 3

This commit is contained in:
Frédéric Péters 2021-05-13 15:55:17 +02:00
parent 36122853fa
commit af4a5292d8
1 changed files with 12 additions and 12 deletions

View File

@ -1,8 +1,8 @@
#! /usr/bin/env python #! /usr/bin/env python3
#%# family=auto #%# family=auto
#%# capabilities=autoconf #%# capabilities=autoconf
import cPickle import pickle
import datetime import datetime
import os import os
import psycopg2 import psycopg2
@ -16,18 +16,18 @@ for dirname in os.listdir('/var/lib/machines/'):
if len(sys.argv) == 2 and sys.argv[1] == 'autoconf': if len(sys.argv) == 2 and sys.argv[1] == 'autoconf':
if base_dir: if base_dir:
print 'yes' print('yes')
else: else:
print 'no' print('no')
sys.exit(0) sys.exit(0)
if len(sys.argv) == 2 and sys.argv[1] == 'config': if len(sys.argv) == 2 and sys.argv[1] == 'config':
print '''graph_title Count of recently submitted forms print('''graph_title Count of recently submitted forms
graph_category entrouvert graph_category entrouvert
count_5m.label Count (5 minutes) count_5m.label Count (5 minutes)
count_1h.label Count (1 hour) count_1h.label Count (1 hour)
count_1d.label Count (k) (1 day) count_1d.label Count (k) (1 day)
''' ''')
sys.exit(0) sys.exit(0)
total_5m = 0 total_5m = 0
@ -45,12 +45,12 @@ for tenant in os.listdir(base_dir):
continue continue
if not os.path.isdir(os.path.join(base_dir, tenant)): if not os.path.isdir(os.path.join(base_dir, tenant)):
continue continue
cfg = cPickle.load(open(os.path.join(base_dir, tenant, 'config.pck'))) cfg = pickle.load(open(os.path.join(base_dir, tenant, 'config.pck'), 'rb'), encoding='utf-8')
if not 'postgresql' in cfg: if 'postgresql' not in cfg:
continue continue
psql_cfg = {} psql_cfg = {}
for k, v in cfg['postgresql'].items(): for k, v in cfg['postgresql'].items():
if v and isinstance(v, basestring): if v and isinstance(v, str):
psql_cfg[k] = v psql_cfg[k] = v
pgconn = psycopg2.connect(**psql_cfg) pgconn = psycopg2.connect(**psql_cfg)
try: try:
@ -62,6 +62,6 @@ for tenant in os.listdir(base_dir):
pass pass
pgconn.close() pgconn.close()
print 'count_5m.value', total_5m print('count_5m.value %s' % total_5m)
print 'count_1h.value', total_1h print('count_1h.value %s' % total_1h)
print 'count_1d.value', int(total_1d / 1000) print('count_1d.value %s' % (total_1d / 1000))