Add Response Time column to health check table

This commit is contained in:
elliotls 2022-06-02 14:59:38 +12:00
parent 7e59b7e88b
commit 1957e273ec
3 changed files with 8 additions and 5 deletions

View File

@ -99,7 +99,7 @@ class EnvironmentCheckSuite
}
/**
* Run this test suite and return the result code of the worst result.
* Run this test suite and return the result code of the worst result and the time it took.
*
* @return EnvironmentCheckSuiteResult
*/
@ -110,13 +110,15 @@ class EnvironmentCheckSuite
foreach ($this->checkInstances() as $check) {
list($checkClass, $checkTitle) = $check;
try {
$startTime = microtime(true);
list($status, $message) = $checkClass->check();
$responseTime = number_format((microtime(true) - $startTime), 4, '.', '') . 's';
// If the check fails, register that as an error
} catch (Exception $e) {
$status = EnvironmentCheck::ERROR;
$message = $e->getMessage();
}
$result->addResult($status, $message, $checkTitle);
$result->addResult($status, $message, $checkTitle, $responseTime);
}
return $result;

View File

@ -35,12 +35,13 @@ class EnvironmentCheckSuiteResult extends ViewableData
* @param string $message
* @param string $checkIdentifier
*/
public function addResult($status, $message, $checkIdentifier)
public function addResult($status, $message, $checkIdentifier, $responseTime)
{
$this->details->push(new ArrayData([
'Check' => $checkIdentifier,
'Status' => $this->statusText($status),
'StatusCode' => $status,
'ResponseTime' => $responseTime,
'Message' => $message,
]));

View File

@ -66,9 +66,9 @@
<% if $IncludeDetails %>
<table>
<tr><th>Check</th> <th>Status</th> <th>Message</th></tr>
<tr><th>Check</th> <th>Status</th> <th>Response Time</th> <th>Message</th></tr>
<% loop $Details %>
<tr><td>$Check</td> <td class="$Status">$Status</td> <td>$Message.XML</td></tr>
<tr><td>$Check</td> <td class="$Status">$Status</td> <td class="$ResponseTime">$ResponseTime</td> <td>$Message.XML</td></tr>
<% end_loop %>
</table>
<% end_if %>