munin: update for python 3 (#63779)

This commit is contained in:
Frédéric Péters 2022-05-27 10:39:54 +02:00
parent 003e834577
commit f0fec15824
4 changed files with 29 additions and 29 deletions

View File

@ -1,4 +1,4 @@
#! /usr/bin/env python
#! /usr/bin/python3
import os
import sys
@ -6,16 +6,16 @@ import sys
tenant = os.path.basename(sys.argv[0]).replace('authentic_count_', '')
if len(sys.argv) == 2 and sys.argv[1] == 'autoconf':
print 'yes'
print('yes')
sys.exit(0)
if len(sys.argv) == 2 and sys.argv[1] == 'config':
print '''graph_title Count of users for %s
print('''graph_title Count of users for %s
graph_category entrouvert
total_count.label Total
total_logged_count.label Total once logged
fc_count.label Total FC
''' % tenant
''' % tenant)
sys.exit(0)
os.system('machinectl shell authentic.node1.prod.saas.entrouvert.org /usr/bin/authentic2-multitenant-manage tenant_command runscript /home/fred//misc-fred/munin/authentic_count_cmd.py compute -d %s' % tenant)

View File

@ -8,6 +8,6 @@ total_user_count = User.objects.filter(userexternalid__isnull=True, ).count()
total_logged_count = User.objects.filter(userexternalid__isnull=True, last_login__isnull=False).count()
fc_count = FcAccount.objects.all().count()
print 'total_count.value', total_user_count
print 'total_logged_count.value', total_logged_count
print 'fc_count.value', fc_count
print('total_count.value', total_user_count)
print('total_logged_count.value', total_logged_count)
print('fc_count.value', fc_count)

View File

@ -1,8 +1,8 @@
#! /usr/bin/env python
#! /usr/bin/python3
#%# family=auto
#%# capabilities=autoconf
import cPickle
import pickle
import os
import psycopg2
import itertools
@ -16,16 +16,16 @@ 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 submitted forms
print('''graph_title Count of submitted forms
graph_category entrouvert
count.label Count
'''
''')
sys.exit(0)
total = 0
@ -37,12 +37,12 @@ for tenant in itertools.chain(os.listdir(base_dir), os.listdir(os.path.join(base
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, (int, str)):
psql_cfg[k] = v
pgconn = psycopg2.connect(**psql_cfg)
cur = pgconn.cursor()
@ -54,4 +54,4 @@ for tenant in itertools.chain(os.listdir(base_dir), os.listdir(os.path.join(base
total += cur.fetchone()[0]
pgconn.close()
print 'count.value', total
print('count.value', total)

View File

@ -1,8 +1,8 @@
#! /usr/bin/env python
#! /usr/bin/python3
#%# family=auto
#%# capabilities=autoconf
import cPickle
import pickle
import itertools
import os
import psycopg2
@ -16,31 +16,31 @@ 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)
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
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
''' % tenant)
sys.exit(0)
for tenant_dir in itertools.chain(os.listdir(base_dir), os.listdir(os.path.join(base_dir, 'tenants'))):
if tenant_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, (int, str)):
psql_cfg[k] = v
pgconn = psycopg2.connect(**psql_cfg)
cur = pgconn.cursor()
@ -53,8 +53,8 @@ for tenant_dir in itertools.chain(os.listdir(base_dir), os.listdir(os.path.join(
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
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