From d2c566360dd940cf4705ce74e91f9ea866857d1a Mon Sep 17 00:00:00 2001
From: DonnieBLT <128622481+DonnieBLT@users.noreply.github.com>
Date: Wed, 1 Jan 2025 13:19:51 -0500
Subject: [PATCH] Add database connection count and Redis stats to status page
---
website/templates/status_page.html | 14 ++++++++++++++
website/views/core.py | 10 ++++++++++
2 files changed, 24 insertions(+)
diff --git a/website/templates/status_page.html b/website/templates/status_page.html
index 25f06a904..b1e7e53a1 100644
--- a/website/templates/status_page.html
+++ b/website/templates/status_page.html
@@ -147,5 +147,19 @@
Top Memory Consumers
+
+
Database Connection Count
+
{{ status.db_connection_count }}
+
+
+
Redis Stats
+
+ {% for key, value in status.redis_stats.items %}
+ -
+ {{ key }}: {{ value }}
+
+ {% endfor %}
+
+
{% endblock content %}
diff --git a/website/views/core.py b/website/views/core.py
index 5b1267a8f..291456504 100644
--- a/website/views/core.py
+++ b/website/views/core.py
@@ -21,6 +21,7 @@
from django.core.exceptions import FieldError
from django.core.files.base import ContentFile
from django.core.files.storage import default_storage
+from django.db import connection
from django.db.models import Count, Q, Sum
from django.db.models.functions import TruncDate
from django.http import Http404, HttpResponse, JsonResponse
@@ -74,6 +75,8 @@ def check_status(request):
"memory_info": psutil.virtual_memory()._asdict(),
"top_memory_consumers": [],
"memory_profiling": {},
+ "db_connection_count": 0,
+ "redis_stats": {},
}
bitcoin_rpc_user = os.getenv("BITCOIN_RPC_USER")
@@ -149,6 +152,13 @@ def check_status(request):
reverse=True,
)[:5]
+ # Get database connection count
+ status["db_connection_count"] = len(connection.queries)
+
+ # Get Redis stats
+ redis_client = redis.StrictRedis(host="localhost", port=6379, db=0)
+ status["redis_stats"] = redis_client.info()
+
# Add memory profiling information
current, peak = tracemalloc.get_traced_memory()
status["memory_profiling"]["current"] = current