diff --git a/cookbook/templates/system.html b/cookbook/templates/system.html index 1c154160c..ca7bd6252 100644 --- a/cookbook/templates/system.html +++ b/cookbook/templates/system.html @@ -177,9 +177,9 @@ {# #}

API Stats

-
User Stats
+
Space Stats
- {% for r in api_user_stats %} + {% for r in api_space_stats %} {% for c in r %} {% endfor %}
@@ -189,7 +189,7 @@
- +
Endpoint Stats
{% for r in api_stats %} diff --git a/cookbook/views/api.py b/cookbook/views/api.py index 53cef92bd..972180a7c 100644 --- a/cookbook/views/api.py +++ b/cookbook/views/api.py @@ -113,7 +113,7 @@ class LoggingMixin(object): if settings.REDIS_HOST: d = date.today().isoformat() - user = request.user + space = request.space endpoint = request.resolver_match.url_name r = redis.StrictRedis( @@ -132,8 +132,8 @@ class LoggingMixin(object): # Use a sorted set to store the user stats, with the score representing # the number of queries the user made total or on a given day. - pipe.zincrby(f'api:user-request-count', 1, user.pk) - pipe.zincrby(f'api:user-request-count:{d}', 1, user.pk) + pipe.zincrby(f'api:space-request-count', 1, space.pk) + pipe.zincrby(f'api:space-request-count:{d}', 1, space.pk) # Use a sorted set to store all the endpoints with score representing # the number of queries the endpoint received total or on a given day. diff --git a/cookbook/views/views.py b/cookbook/views/views.py index 3b5e2d22c..05c3a0d4b 100644 --- a/cookbook/views/views.py +++ b/cookbook/views/views.py @@ -356,13 +356,13 @@ def system(request): ) api_stats = [['Endpoint', 'Total']] - api_user_stats = [['User', 'Total']] + api_space_stats = [['User', 'Total']] total_stats = ['All', int(r.get('api:request-count'))] for i in range(0, 6): d = (date.today() - timedelta(days=i)).isoformat() api_stats[0].append(d) - api_user_stats[0].append(d) + api_space_stats[0].append(d) total_stats.append(int(r.get(f'api:request-count:{d}')) if r.get(f'api:request-count:{d}') else 0) api_stats.append(total_stats) @@ -375,19 +375,19 @@ def system(request): endpoint_stats.append(r.zscore(f'api:endpoint-request-count:{d}', endpoint)) api_stats.append(endpoint_stats) - for x in r.zrange('api:user-request-count', 0, 20, withscores=True, desc=True): - u = x[0].decode('utf-8') - user_stats = [User.objects.get(pk=u).username, x[1]] + for x in r.zrange('api:space-request-count', 0, 20, withscores=True, desc=True): + s = x[0].decode('utf-8') + space_stats = [Space.objects.get(pk=s).name, x[1]] for i in range(0, 6): d = (date.today() - timedelta(days=i)).isoformat() - user_stats.append(r.zscore(f'api:user-request-count:{d}', u)) - api_user_stats.append(user_stats) + space_stats.append(r.zscore(f'api:space-request-count:{d}', s)) + api_space_stats.append(space_stats) return render( request, 'system.html', { 'gunicorn_media': settings.GUNICORN_MEDIA, 'debug': settings.DEBUG, 'postgres': postgres, 'postgres_version': postgres_ver, 'postgres_status': database_status, 'postgres_message': database_message, 'version_info': VERSION_INFO, 'plugins': PLUGINS, 'secret_key': secret_key, 'orphans': orphans, 'migration_info': migration_info, - 'missing_migration': missing_migration, 'allowed_hosts': settings.ALLOWED_HOSTS, 'api_stats': api_stats, 'api_user_stats': api_user_stats + 'missing_migration': missing_migration, 'allowed_hosts': settings.ALLOWED_HOSTS, 'api_stats': api_stats, 'api_space_stats': api_space_stats })