Skip to content
Snippets Groups Projects
Verified Commit 0ff596d3 authored by Tom Teichler's avatar Tom Teichler :beers:
Browse files

Implement django-health-check

parent 94958995
No related branches found
No related tags found
1 merge request!315Resolve "Implement django-health-check"
Pipeline #2794 passed
......@@ -85,6 +85,11 @@ INSTALLED_APPS = [
"django_otp",
"otp_yubikey",
"aleksis.core",
"health_check",
"health_check.db",
"health_check.cache",
"health_check.storage",
"health_check.contrib.psutil",
"dynamic_preferences",
"dynamic_preferences.users.apps.UserPreferencesConfig",
"impersonate",
......@@ -419,7 +424,12 @@ if _settings.get("twilio.sid", None):
TWILIO_CALLER_ID = _settings.get("twilio.callerid")
if _settings.get("celery.enabled", False):
INSTALLED_APPS += ("django_celery_beat", "django_celery_results", "celery_progress")
INSTALLED_APPS += (
"django_celery_beat",
"django_celery_results",
"celery_progress",
"health_check.contrib.celery",
)
CELERY_BROKER_URL = _settings.get("celery.broker", "redis://localhost")
CELERY_RESULT_BACKEND = "django-db"
CELERY_CACHE_BACKEND = "django-cache"
......@@ -656,3 +666,8 @@ else:
HAYSTACK_SEARCH_RESULTS_PER_PAGE = 10
DJANGO_EASY_AUDIT_WATCH_REQUEST_EVENTS = False
HEALTH_CHECK = {
"DISK_USAGE_MAX": _settings.get("health.disk_usage_max_percent", 90),
"MEMORY_MIN": _settings.get("health.memory_min_mb", 500),
}
......@@ -63,6 +63,43 @@
</div>
</div>
{# Health checks #}
<div class="card">
<div class="card-content">
<span class="card-title"> {% blocktrans %}System health checks{% endblocktrans %}</span>
<table>
<thead>
<tr>
<th colspan="2">{% trans "Service" %}</th>
<th>{% trans "Status" %}</th>
<th>{% trans "Time taken" %}</th>
</tr>
</thead>
<tbody>
{% for plugin in plugins %}
<tr>
<td>
<a class="tooltipped" data-position="top" data-tooltip="{{ plugin.pretty_status }}">
{% if plugin.status %}
<i class="material-icons green-text" aria-hidden="true" title="{{ plugin.pretty_status }}">check</i>
{% else %}
<i class="material-icons red-text" aria-hidden="true" title="{{ plugin.pretty_status }}">warning</i>
{% endif %}
</a>
</td>
<td>{{ plugin.identifier }}</td>
<td>
{{ plugin.pretty_status }}
</td>
<td>{{ plugin.time_taken|floatformat:4 }} {% trans "seconds" %}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% if tasks %}
<div class="card">
......
......@@ -9,6 +9,7 @@ from django.views.i18n import JavaScriptCatalog
import calendarweek.django
import debug_toolbar
from django_js_reverse.views import urls_js
from health_check.urls import urlpatterns as health_urls
from two_factor.urls import urlpatterns as tf_urls
from . import views
......@@ -19,7 +20,7 @@ urlpatterns = [
path("about/", views.about, name="about_aleksis"),
path("admin/", admin.site.urls),
path("data_management/", views.data_management, name="data_management"),
path("status/", views.system_status, name="system_status"),
path("status/", views.SystemStatus.as_view(), name="system_status"),
path("", include(tf_urls)),
path("accounts/logout/", auth_views.LogoutView.as_view(), name="logout"),
path("school_terms/", views.SchoolTermListView.as_view(), name="school_terms"),
......@@ -147,6 +148,7 @@ urlpatterns = [
{"registry_name": "group"},
name="preferences_group",
),
path("health/", include(health_urls)),
]
# Serve static files from STATIC_ROOT to make it work with runserver
......
......@@ -15,6 +15,7 @@ from guardian.shortcuts import get_objects_for_user
from haystack.inputs import AutoQuery
from haystack.query import SearchQuerySet
from haystack.views import SearchView
from health_check.views import MainView
from rules.contrib.views import PermissionRequiredMixin, permission_required
from .filters import GroupFilter
......@@ -340,22 +341,28 @@ def data_management(request: HttpRequest) -> HttpResponse:
return render(request, "core/management/data_management.html", context)
@permission_required("core.view_system_status")
def system_status(request: HttpRequest) -> HttpResponse:
class SystemStatus(MainView, PermissionRequiredMixin):
"""View giving information about the system status."""
template_name = "core/pages/system_status.html"
permission_required = "core.view_system_status"
context = {}
if "django_celery_results" in settings.INSTALLED_APPS:
from django_celery_results.models import TaskResult # noqa
from celery.task.control import inspect # noqa
if inspect().registered_tasks():
job_list = list(inspect().registered_tasks().values())[0]
results = []
for job in job_list:
results.append(TaskResult.objects.filter(task_name=job).last())
context["tasks"] = results
return render(request, "core/pages/system_status.html", context)
def get(self, request, *args, **kwargs):
status_code = 500 if self.errors else 200
if "django_celery_results" in settings.INSTALLED_APPS:
from django_celery_results.models import TaskResult # noqa
from celery.task.control import inspect # noqa
if inspect().registered_tasks():
job_list = list(inspect().registered_tasks().values())[0]
results = []
for job in job_list:
results.append(TaskResult.objects.filter(task_name=job).last())
context = {"plugins": self.plugins, "status_code": status_code}
return self.render_to_response(context, status=status_code)
@permission_required(
......
This diff is collapsed.
......@@ -85,6 +85,8 @@ spdx-license-list = "^0.5.0"
license-expression = "^1.2"
django-reversion = "^3.0.7"
django-favicon-plus-reloaded = "^1.0.4"
django-health-check = "^3.12.1"
psutil = "^5.7.0"
celery-progress = "^0.0.10"
[tool.poetry.extras]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment