New status info

This commit is contained in:
Oliver Walters 2021-03-06 21:41:19 +11:00
parent 7bec3ff5dd
commit 45b3c68930
3 changed files with 45 additions and 15 deletions

View File

@ -30,10 +30,20 @@ def health_status(request):
request._inventree_health_status = True
return {
"system_healthy": InvenTree.status.check_system_health(),
status = {
'django_q_running': InvenTree.status.is_q_cluster_running(),
}
all_healthy = True
for k in status.keys():
if status[k] is not True:
all_healthy = False
status['system_healthy'] = all_healthy
return status
def status_codes(request):
"""

View File

@ -1,15 +1,32 @@
"""
Provides system status functionality checks.
"""
# -*- coding: utf-8 -*-
from django.utils.translation import ugettext as _
from __future__ import unicode_literals
import logging
from django.utils.translation import ugettext as _
from django_q.monitor import Stat
logger = logging.getLogger(__name__)
def is_q_cluster_running(**kwargs):
"""
Return True if at least one cluster worker is running
"""
clusters = Stat.get_all()
for cluster in clusters:
print("Cluster:", cluster)
return len(clusters) > 0
def check_system_health(**kwargs):
"""
Check that the InvenTree system is running OK.
@ -19,7 +36,7 @@ def check_system_health(**kwargs):
result = True
if not check_celery_worker(**kwargs):
if not is_q_cluster_running(**kwargs):
result = False
logger.warning(_("Celery worker check failed"))
@ -27,13 +44,3 @@ def check_system_health(**kwargs):
logger.warning(_("InvenTree system health checks failed"))
return result
def check_celery_worker(**kwargs):
"""
Check that a celery worker is running.
"""
# TODO - Checks that the configured celery worker thing is running
return True

View File

@ -13,8 +13,9 @@
<td>{% trans "Instance Name" %}</td>
<td>{% inventree_instance_name %}</td>
</tr>
{% if user.is_staff %}
<tr>
<td><span class='fas fa-exclamation-triangle'></span></td>
<td><span class='fas fa-server'></span></td>
<td>{% trans "Server status" %}</td>
<td>
{% if system_healthy %}
@ -24,6 +25,18 @@
{% endif %}
</td>
</tr>
<tr>
<td><span class='fas fa-tasks'></span></td>
<td>{% trans "Background Worker" %}</td>
<td>
{% if django_q_running %}
<span class='label label-green'>{% trans "Operational" %}</span>
{% else %}
<span class='label label-red'>{% trans "Not running" %}</span>
{% endif %}
</td>
</tr>
{% endif %}
{% if not system_healthy %}
{% for issue in system_issues %}