mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-01 04:10:06 -05:00
switched to space stats
This commit is contained in:
@@ -177,9 +177,9 @@
|
|||||||
{# </textarea>#}
|
{# </textarea>#}
|
||||||
|
|
||||||
<h4 class="mt-3">API Stats</h4>
|
<h4 class="mt-3">API Stats</h4>
|
||||||
<h6 >User Stats</h6>
|
<h6 >Space Stats</h6>
|
||||||
<table class="table table-bordered table-striped">
|
<table class="table table-bordered table-striped">
|
||||||
{% for r in api_user_stats %}
|
{% for r in api_space_stats %}
|
||||||
<tr>
|
<tr>
|
||||||
{% for c in r %}
|
{% for c in r %}
|
||||||
<td>
|
<td>
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ class LoggingMixin(object):
|
|||||||
|
|
||||||
if settings.REDIS_HOST:
|
if settings.REDIS_HOST:
|
||||||
d = date.today().isoformat()
|
d = date.today().isoformat()
|
||||||
user = request.user
|
space = request.space
|
||||||
endpoint = request.resolver_match.url_name
|
endpoint = request.resolver_match.url_name
|
||||||
|
|
||||||
r = redis.StrictRedis(
|
r = redis.StrictRedis(
|
||||||
@@ -132,8 +132,8 @@ class LoggingMixin(object):
|
|||||||
|
|
||||||
# Use a sorted set to store the user stats, with the score representing
|
# 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.
|
# 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:space-request-count', 1, space.pk)
|
||||||
pipe.zincrby(f'api:user-request-count:{d}', 1, user.pk)
|
pipe.zincrby(f'api:space-request-count:{d}', 1, space.pk)
|
||||||
|
|
||||||
# Use a sorted set to store all the endpoints with score representing
|
# 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.
|
# the number of queries the endpoint received total or on a given day.
|
||||||
|
|||||||
@@ -356,13 +356,13 @@ def system(request):
|
|||||||
)
|
)
|
||||||
|
|
||||||
api_stats = [['Endpoint', 'Total']]
|
api_stats = [['Endpoint', 'Total']]
|
||||||
api_user_stats = [['User', 'Total']]
|
api_space_stats = [['User', 'Total']]
|
||||||
total_stats = ['All', int(r.get('api:request-count'))]
|
total_stats = ['All', int(r.get('api:request-count'))]
|
||||||
|
|
||||||
for i in range(0, 6):
|
for i in range(0, 6):
|
||||||
d = (date.today() - timedelta(days=i)).isoformat()
|
d = (date.today() - timedelta(days=i)).isoformat()
|
||||||
api_stats[0].append(d)
|
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)
|
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)
|
api_stats.append(total_stats)
|
||||||
@@ -375,19 +375,19 @@ def system(request):
|
|||||||
endpoint_stats.append(r.zscore(f'api:endpoint-request-count:{d}', endpoint))
|
endpoint_stats.append(r.zscore(f'api:endpoint-request-count:{d}', endpoint))
|
||||||
api_stats.append(endpoint_stats)
|
api_stats.append(endpoint_stats)
|
||||||
|
|
||||||
for x in r.zrange('api:user-request-count', 0, 20, withscores=True, desc=True):
|
for x in r.zrange('api:space-request-count', 0, 20, withscores=True, desc=True):
|
||||||
u = x[0].decode('utf-8')
|
s = x[0].decode('utf-8')
|
||||||
user_stats = [User.objects.get(pk=u).username, x[1]]
|
space_stats = [Space.objects.get(pk=s).name, x[1]]
|
||||||
for i in range(0, 6):
|
for i in range(0, 6):
|
||||||
d = (date.today() - timedelta(days=i)).isoformat()
|
d = (date.today() - timedelta(days=i)).isoformat()
|
||||||
user_stats.append(r.zscore(f'api:user-request-count:{d}', u))
|
space_stats.append(r.zscore(f'api:space-request-count:{d}', s))
|
||||||
api_user_stats.append(user_stats)
|
api_space_stats.append(space_stats)
|
||||||
|
|
||||||
return render(
|
return render(
|
||||||
request, 'system.html', {
|
request, 'system.html', {
|
||||||
'gunicorn_media': settings.GUNICORN_MEDIA, 'debug': settings.DEBUG, 'postgres': postgres, 'postgres_version': postgres_ver, 'postgres_status': database_status,
|
'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,
|
'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
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user