Переглянути джерело

HUE-8749 [stats] Also add the number of login sessions

Romain 6 роки тому
батько
коміт
732f3d25ca

+ 1 - 0
desktop/libs/notebook/src/notebook/connectors/base.py

@@ -14,6 +14,7 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
+
 import json
 import logging
 import re

+ 1 - 1
desktop/libs/notebook/src/notebook/management/commands/send_query_stats.py

@@ -31,7 +31,7 @@ class Command(BaseCommand):
   def handle(self, *args, **options):
     print('Starting...')
     stats = Analytics.admin_stats()
-    msg = '\n\n'.join(['%s\t=\t%s' % stat for stat in stats])
+    msg = '\n'.join(['%s\t=\t%s' % stat for stat in stats])
 
     mail.mail_admins(subject='Query Stats', message=msg, fail_silently=True)
 

+ 3 - 0
desktop/libs/notebook/src/notebook/models.py

@@ -26,6 +26,7 @@ import uuid
 from datetime import timedelta
 
 from django.contrib.auth.models import User
+from django.contrib.sessions.models import Session
 from django.db.models import Count
 from django.db.models.functions import Trunc
 from django.utils.html import escape
@@ -480,11 +481,13 @@ class Analytics():
 
     stats.append(('Last modified', '1 week'))
     stats.append(('Users', User.objects.filter(last_login__gte=one_week).count()))
+    stats.append(('Sessions', Session.objects.filter(expire_date__gte=one_week).count()))
     stats.append(('Executed queries', Document2.objects.filter(last_modified__gte=one_week, is_history=True, type__startswith='query-').count()))
     stats.append(('Saved queries', Document2.objects.filter(last_modified__gte=one_week, is_history=False, type__startswith='query-').count()))
 
     stats.append(('\nAll', ''))
     stats.append(('Active users 30 days', User.objects.filter(last_login__gte=one_month).count()))
+    stats.append(('Sessions 30 days', Session.objects.filter(expire_date__gte=one_month).count()))
     stats.append(('Active users 90 days', User.objects.filter(last_login__gte=three_months).count()))
 
     return stats