publish authentic stats (#5205)

This commit is contained in:
Frédéric Péters 2014-07-23 19:14:50 +02:00
parent b7edf2634e
commit 441f51006f
2 changed files with 48 additions and 0 deletions

8
idp/scripts/authentic_stats Executable file
View File

@ -0,0 +1,8 @@
#! /bin/sh -e
. /etc/authentic2/db.conf
T=$(tempfile --mode=0644)
python /usr/local/sbin/authentic_stats.py > $T
cp $T /var/lib/authentic2/static/stats.json
rm -f $T

View File

@ -0,0 +1,40 @@
#! /usr/bin/env python
import psycopg2
import os
import json
pgconn = psycopg2.connect(
database=os.environ.get('DATABASE_NAME'),
user=os.environ.get('DATABASE_USER'),
password=os.environ.get('DATABASE_PASSWORD'),
host=os.environ.get('DATABASE_HOST'))
cur = pgconn.cursor()
result = {}
cur.execute('SELECT COUNT(*) FROM auth_user')
result['users_count'] = cur.fetchone()[0]
cur.execute("""select count(*) from auth_user
where last_login > (current_timestamp - interval '1 day')""")
result['users_last_connection_less_than_one_day_ago'] = cur.fetchone()[0]
cur.execute("""select count(*) from auth_user
where last_login > (current_timestamp - interval '1 hour')""")
result['users_last_connection_less_than_one_hour_ago'] = cur.fetchone()[0]
cur.execute("""select count(*) from saml_libertyfederation
where sp_id IS NOT NULL""")
result['active_federations'] = cur.fetchone()[0]
cur.execute("""select saml_libertyprovider.slug, count(*) from saml_libertyfederation, saml_libertyprovider
where saml_libertyprovider.id = saml_libertyfederation.sp_id
group by saml_libertyprovider.slug""")
while True:
row = cur.fetchone()
if not row:
break
result['%s_active_federations' % row[0]] = row[1]
print json.dumps(result)