Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Added check status time #1

Merged
merged 1 commit into from
Apr 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions health_check/backends/base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import timeit
from django.core.files.storage import get_storage_class
from django.core.files.base import ContentFile
import logging
Expand Down Expand Up @@ -35,15 +36,24 @@ class ServiceReturnedUnexpectedResult(HealthCheckException):


class BaseHealthCheckBackend(object):
_check_status_time = 'Not calculated'

def check_status(self):
return None

@property
def check_status_time(self):
if type(self._check_status_time) == float:
return u'%.3f s' % self._check_status_time
return self._check_status_time

@property
def status(self):
if not getattr(self, "_status", False):
try:
start_time = timeit.default_timer()
setattr(self, "_status", self.check_status())
self._check_status_time = (timeit.default_timer() - start_time)
except (ServiceUnavailable, ServiceReturnedUnexpectedResult, ) as e:
logger.warning(e)
setattr(self, "_status", e.code)
Expand Down
11 changes: 11 additions & 0 deletions health_check/templates/health_check/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
font-family: 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;
font-size: 22px;
}
th
{
text-align: left;
}
td.status_1, td.status_True
{
background-color: #0f0;
Expand All @@ -50,11 +54,18 @@
<div class="container">
<h1>ePantry System status</h1>
<table>
<tr>
<th></th>
<th>Plugin</th>
<th>Status</th>
<th>Check status time</th>
</tr>
{% for plugin in plugins %}
<tr>
<td class="status_{{ plugin.status }}"></td>
<td>{{ plugin.identifier }}</td>
<td>{{ plugin.pretty_status }}</td>
<td>{{ plugin.check_status_time }}</td>
</tr>
{% endfor %}
</table>
Expand Down