Skip to content

Commit

Permalink
Add database connection count and Redis stats to status page
Browse files Browse the repository at this point in the history
  • Loading branch information
DonnieBLT committed Jan 1, 2025
1 parent 35e8af5 commit d2c5663
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
14 changes: 14 additions & 0 deletions website/templates/status_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,19 @@ <h3>Top Memory Consumers</h3>
</ul>
</div>
</div>
<div class="status-card">
<h3>Database Connection Count</h3>
<p>{{ status.db_connection_count }}</p>
</div>
<div class="status-card">
<h3>Redis Stats</h3>
<ul>
{% for key, value in status.redis_stats.items %}
<li>
<strong>{{ key }}</strong>: {{ value }}
</li>
{% endfor %}
</ul>
</div>
</div>
{% endblock content %}
10 changes: 10 additions & 0 deletions website/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d2c5663

Please sign in to comment.