Skip to content

Commit 7dba36d

Browse files
committed
switched to space stats
1 parent 0dea5c9 commit 7dba36d

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

cookbook/templates/system.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ <h4 class="mt-3">{% trans 'Migrations' %}
177177
{# </textarea>#}
178178

179179
<h4 class="mt-3">API Stats</h4>
180-
<h6 >User Stats</h6>
180+
<h6 >Space Stats</h6>
181181
<table class="table table-bordered table-striped">
182-
{% for r in api_user_stats %}
182+
{% for r in api_space_stats %}
183183
<tr>
184184
{% for c in r %}
185185
<td>
@@ -189,7 +189,7 @@ <h6 >User Stats</h6>
189189
</tr>
190190
{% endfor %}
191191
</table>
192-
192+
193193
<h6 >Endpoint Stats</h6>
194194
<table class="table table-bordered table-striped">
195195
{% for r in api_stats %}

cookbook/views/api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def initial(self, request, *args, **kwargs):
113113

114114
if settings.REDIS_HOST:
115115
d = date.today().isoformat()
116-
user = request.user
116+
space = request.space
117117
endpoint = request.resolver_match.url_name
118118

119119
r = redis.StrictRedis(
@@ -132,8 +132,8 @@ def initial(self, request, *args, **kwargs):
132132

133133
# Use a sorted set to store the user stats, with the score representing
134134
# the number of queries the user made total or on a given day.
135-
pipe.zincrby(f'api:user-request-count', 1, user.pk)
136-
pipe.zincrby(f'api:user-request-count:{d}', 1, user.pk)
135+
pipe.zincrby(f'api:space-request-count', 1, space.pk)
136+
pipe.zincrby(f'api:space-request-count:{d}', 1, space.pk)
137137

138138
# Use a sorted set to store all the endpoints with score representing
139139
# the number of queries the endpoint received total or on a given day.

cookbook/views/views.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -356,13 +356,13 @@ def system(request):
356356
)
357357

358358
api_stats = [['Endpoint', 'Total']]
359-
api_user_stats = [['User', 'Total']]
359+
api_space_stats = [['User', 'Total']]
360360
total_stats = ['All', int(r.get('api:request-count'))]
361361

362362
for i in range(0, 6):
363363
d = (date.today() - timedelta(days=i)).isoformat()
364364
api_stats[0].append(d)
365-
api_user_stats[0].append(d)
365+
api_space_stats[0].append(d)
366366
total_stats.append(int(r.get(f'api:request-count:{d}')) if r.get(f'api:request-count:{d}') else 0)
367367

368368
api_stats.append(total_stats)
@@ -375,19 +375,19 @@ def system(request):
375375
endpoint_stats.append(r.zscore(f'api:endpoint-request-count:{d}', endpoint))
376376
api_stats.append(endpoint_stats)
377377

378-
for x in r.zrange('api:user-request-count', 0, 20, withscores=True, desc=True):
379-
u = x[0].decode('utf-8')
380-
user_stats = [User.objects.get(pk=u).username, x[1]]
378+
for x in r.zrange('api:space-request-count', 0, 20, withscores=True, desc=True):
379+
s = x[0].decode('utf-8')
380+
space_stats = [Space.objects.get(pk=s).name, x[1]]
381381
for i in range(0, 6):
382382
d = (date.today() - timedelta(days=i)).isoformat()
383-
user_stats.append(r.zscore(f'api:user-request-count:{d}', u))
384-
api_user_stats.append(user_stats)
383+
space_stats.append(r.zscore(f'api:space-request-count:{d}', s))
384+
api_space_stats.append(space_stats)
385385

386386
return render(
387387
request, 'system.html', {
388388
'gunicorn_media': settings.GUNICORN_MEDIA, 'debug': settings.DEBUG, 'postgres': postgres, 'postgres_version': postgres_ver, 'postgres_status': database_status,
389389
'postgres_message': database_message, 'version_info': VERSION_INFO, 'plugins': PLUGINS, 'secret_key': secret_key, 'orphans': orphans, 'migration_info': migration_info,
390-
'missing_migration': missing_migration, 'allowed_hosts': settings.ALLOWED_HOSTS, 'api_stats': api_stats, 'api_user_stats': api_user_stats
390+
'missing_migration': missing_migration, 'allowed_hosts': settings.ALLOWED_HOSTS, 'api_stats': api_stats, 'api_space_stats': api_space_stats
391391
})
392392

393393

0 commit comments

Comments
 (0)