munin: update publik_recent_count to use python 3
This commit is contained in:
parent
36122853fa
commit
af4a5292d8
|
@ -1,8 +1,8 @@
|
|||
#! /usr/bin/env python
|
||||
#! /usr/bin/env python3
|
||||
#%# family=auto
|
||||
#%# capabilities=autoconf
|
||||
|
||||
import cPickle
|
||||
import pickle
|
||||
import datetime
|
||||
import os
|
||||
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 base_dir:
|
||||
print 'yes'
|
||||
print('yes')
|
||||
else:
|
||||
print 'no'
|
||||
print('no')
|
||||
sys.exit(0)
|
||||
|
||||
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
|
||||
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
|
||||
|
@ -45,12 +45,12 @@ for tenant in os.listdir(base_dir):
|
|||
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:
|
||||
cfg = pickle.load(open(os.path.join(base_dir, tenant, 'config.pck'), 'rb'), encoding='utf-8')
|
||||
if 'postgresql' not in cfg:
|
||||
continue
|
||||
psql_cfg = {}
|
||||
for k, v in cfg['postgresql'].items():
|
||||
if v and isinstance(v, basestring):
|
||||
if v and isinstance(v, str):
|
||||
psql_cfg[k] = v
|
||||
pgconn = psycopg2.connect(**psql_cfg)
|
||||
try:
|
||||
|
@ -62,6 +62,6 @@ for tenant in os.listdir(base_dir):
|
|||
pass
|
||||
pgconn.close()
|
||||
|
||||
print 'count_5m.value', total_5m
|
||||
print 'count_1h.value', total_1h
|
||||
print 'count_1d.value', int(total_1d / 1000)
|
||||
print('count_5m.value %s' % total_5m)
|
||||
print('count_1h.value %s' % total_1h)
|
||||
print('count_1d.value %s' % (total_1d / 1000))
|
||||
|
|
Loading…
Reference in New Issue