Adding file size and archive count to rss feed fetch status board.

This commit is contained in:
Samuel Clay 2022-09-11 21:54:06 -04:00
parent 57cf284f13
commit f93eb2520c
4 changed files with 17 additions and 7 deletions

View file

@ -74,6 +74,7 @@ def slow(request):
user_id_counts = {}
path_counts = {}
users = {}
for minutes_ago in range(60*6):
dt_ago = now - datetime.timedelta(minutes=minutes_ago)
dt_ago_str = dt_ago.strftime("%a %b %-d, %Y %H:%M")
@ -105,6 +106,7 @@ def slow(request):
user_counts = []
for user_id, count in user_id_counts.items():
user_counts.append({'user': users[user_id], 'count': count})
return render(request, 'statistics/slow.xhtml', {
'all_queries': all_queries,
'user_counts': user_counts,

View file

@ -2,7 +2,7 @@
{% load utils_tags tz %}
{% block bodyclass %}NB-body-status{% endblock %}
{% block bodyclass %}NB-body-status NB-static{% endblock %}
{% block content %}
@ -21,6 +21,7 @@
<th style="white-space: nowrap">Last Update<br>Next Update</th>
<th>Min to<br>next update</th>
<th>Decay</th>
<th>Last fetch</th>
<th>Subs</th>
<th>Active</th>
<th>Premium</th>
@ -29,11 +30,13 @@
<th>Act. Prem</th>
<th>Per Month</th>
<th>Last Month</th>
<th>In Archive</th>
<th>File size (b)</th>
</tr>
{% for feed in feeds %}
<tr>
<td>{{ feed.pk }}</td>
<td><img class="NB-favicon" src="/rss_feeds/icon/{{ feed.pk }}" /> {{ feed.feed_title|truncatewords:4 }}</td>
<td title="{{ feed.feed_address }}"><img class="NB-favicon" src="/rss_feeds/icon/{{ feed.pk }}" /> {{ feed.feed_title|truncatewords:4 }}</td>
<td>{{ feed.last_update|smooth_timedelta }}</td>
<td class="NB-status-update" style="white-space: nowrap">
{% localdatetime feed.last_update "%b %d, %Y %H:%M:%S" %}
@ -42,6 +45,7 @@
</td>
<td>{{ feed.next_scheduled_update|smooth_timedelta }}</td>
<td>{{ feed.min_to_decay }}</td>
<td>{{ feed.last_load_time }}</td>
<td>{{ feed.num_subscribers }}</td>
<td style="color: {% if feed.active_subscribers == 0 %}lightgrey{% else %}darkblue{% endif %}">{{ feed.active_subscribers }}</td>
<td style="color: {% if feed.premium_subscribers == 0 %}lightgrey{% else %}darkblue{% endif %}">{{ feed.premium_subscribers }}</td>
@ -50,6 +54,8 @@
<td style="color: {% if feed.active_premium_subscribers == 0 %}lightgrey{% else %}darkblue{% endif %}">{{ feed.active_premium_subscribers }}</td>
<td style="color: {% if feed.average_stories_per_month == 0 %}lightgrey{% else %}{% endif %}">{{ feed.average_stories_per_month }}</td>
<td style="color: {% if feed.stories_last_month == 0 %}lightgrey{% else %}{% endif %}">{{ feed.stories_last_month }}</td>
<td style="color: {% if feed.archive_count == 0 %}lightgrey{% else %}{% endif %}">{{ feed.archive_count }}</td>
<td style="color: {% if feed.fs_size_bytes == 0 %}lightgrey{% else %}{% endif %}">{{ feed.fs_size_bytes|commify }}</td>
</tr>
{% endfor %}

View file

@ -12,7 +12,7 @@
<table class="NB-status">
{% for user_count in user_counts %}
<tr>
{% if forloop.first %}<td rowspan={{user_counts|length}}><h2>Users</h2>{% endif %}
{% if forloop.first %}<td rowspan={{user_counts|length}} valign=top><b>Users</b>{% endif %}
<td><b>{{ user_count.user }}</b></td>
<td>{{ user_count.count }}</td>
</tr>
@ -23,7 +23,7 @@
<table class="NB-status">
{% for path, count in path_counts.items %}
<tr>
{% if forloop.first %}<td rowspan={{user_counts|length}}><h2>Paths</h2>{% endif %}
{% if forloop.first %}<td rowspan={{path_counts|length}} valign=top><b>Paths</b>{% endif %}
<td><b>{{ path }}</b></td>
<td>{{ count }}</td>
</tr>

View file

@ -10,6 +10,8 @@ IGNORE_PATHS = [
"/_haproxychk",
]
RECORD_SLOW_REQUESTS_ABOVE_SECONDS = 10
class DumpRequestMiddleware:
def process_request(self, request):
if settings.DEBUG and request.path not in IGNORE_PATHS:
@ -46,7 +48,7 @@ class DumpRequestMiddleware:
if hasattr(request, 'start_time'):
seconds = time.time() - request.start_time
if seconds > 10:
if seconds > RECORD_SLOW_REQUESTS_ABOVE_SECONDS:
r = redis.Redis(connection_pool=settings.REDIS_STATISTICS_POOL)
pipe = r.pipeline()
minute = round_time(round_to=60)
@ -54,9 +56,9 @@ class DumpRequestMiddleware:
user_id = request.user.pk if request.user.is_authenticated else "0"
data_string = None
if request.method == "GET":
data_string = ', '.join([f"{key}={value}" for key, value in request.GET.items()])
data_string = ' '.join([f"{key}={value}" for key, value in request.GET.items()])
elif request.method == "GET":
data_string = ', '.join([f"{key}={value}" for key, value in request.POST.items()])
data_string = ' '.join([f"{key}={value}" for key, value in request.POST.items()])
data = {
"user_id": user_id,
"time": round(seconds, 2),