2019-09-12 22:15:42 +02:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
2020-04-20 00:38:50 +02:00
|
|
|
<title>Health Dashboard</title>
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
2019-09-12 22:15:42 +02:00
|
|
|
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
2019-12-28 18:19:52 +01:00
|
|
|
<style>
|
2020-04-20 00:38:50 +02:00
|
|
|
html, body {
|
|
|
|
background-color: #f7f9fb;
|
|
|
|
}
|
|
|
|
html {
|
|
|
|
height: 100%;
|
|
|
|
}
|
2020-03-10 23:34:32 +01:00
|
|
|
#results div.container:first-child {
|
|
|
|
border-top-left-radius: 3px;
|
|
|
|
border-top-right-radius: 3px;
|
|
|
|
}
|
|
|
|
#results div.container:last-child {
|
|
|
|
border-bottom-left-radius: 3px;
|
|
|
|
border-bottom-right-radius: 3px;
|
|
|
|
border-bottom-width: 1px;
|
|
|
|
border-color: #dee2e6;
|
|
|
|
border-style: solid;
|
|
|
|
}
|
|
|
|
.status-ok {
|
2019-12-28 18:19:52 +01:00
|
|
|
display: inline-block;
|
2020-03-10 23:34:32 +01:00
|
|
|
width: 1%;
|
|
|
|
height: 20px;
|
|
|
|
margin-right: 4px;
|
|
|
|
background-color: #28a745;
|
2019-12-28 18:19:52 +01:00
|
|
|
}
|
2020-04-20 00:38:50 +02:00
|
|
|
.status {
|
|
|
|
cursor: pointer;
|
2020-08-22 04:07:46 +02:00
|
|
|
transition: all 500ms ease-in-out;
|
|
|
|
overflow-x: hidden;
|
|
|
|
padding: .25em 0;
|
|
|
|
color: white;
|
|
|
|
}
|
|
|
|
.title {
|
|
|
|
font-size: 2.5rem;
|
2020-04-20 00:38:50 +02:00
|
|
|
}
|
|
|
|
.status:hover {
|
|
|
|
opacity: 0.7;
|
|
|
|
transition: opacity 100ms ease-in-out;
|
2020-08-22 04:07:46 +02:00
|
|
|
color: black;
|
2020-04-20 00:38:50 +02:00
|
|
|
}
|
|
|
|
.status-over-time {
|
|
|
|
overflow: auto;
|
|
|
|
}
|
|
|
|
.status-over-time>span:not(:last-child) {
|
|
|
|
margin-left: 2px;
|
|
|
|
}
|
|
|
|
.status-time-ago {
|
|
|
|
color: #6a737d;
|
|
|
|
opacity: 0.5;
|
|
|
|
margin-top: 5px;
|
|
|
|
}
|
2020-08-22 04:07:46 +02:00
|
|
|
.status-min-max-ms {
|
|
|
|
overflow-x: hidden;
|
|
|
|
}
|
2020-04-20 00:38:50 +02:00
|
|
|
#tooltip {
|
|
|
|
position: fixed;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
background-color: white;
|
|
|
|
border: 1px solid lightgray;
|
|
|
|
border-radius: 4px;
|
|
|
|
padding: 6px;
|
|
|
|
font-size: 13px;
|
|
|
|
}
|
|
|
|
#tooltip code {
|
|
|
|
color: #212529;
|
|
|
|
line-height: 1;
|
|
|
|
}
|
|
|
|
#tooltip .tooltip-title {
|
|
|
|
font-weight: bold;
|
|
|
|
margin-bottom: 0;
|
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
#tooltip .tooltip-title {
|
|
|
|
margin-top: 8px;
|
|
|
|
}
|
|
|
|
#tooltip>.tooltip-title:first-child {
|
|
|
|
margin-top: 0;
|
|
|
|
}
|
2019-12-28 18:19:52 +01:00
|
|
|
</style>
|
2019-09-12 22:15:42 +02:00
|
|
|
</head>
|
|
|
|
<body>
|
2020-08-22 04:07:46 +02:00
|
|
|
<div class="container my-3 rounded p-3 border shadow">
|
|
|
|
<div class="mb-2">
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-8 text-left my-auto">
|
|
|
|
<div class="title display-4">Health Status</div>
|
|
|
|
</div>
|
|
|
|
<div class="col-4 text-right">
|
|
|
|
<img src="logo.png" alt="GaTuS" style="position: relative; min-width: 50px; max-width: 200px; width: 20%;"/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-09-12 22:15:42 +02:00
|
|
|
</div>
|
2020-04-20 00:38:50 +02:00
|
|
|
<div id="results"></div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div id="tooltip" style="display: none">
|
|
|
|
<div class="tooltip-title">Timestamp:</div>
|
|
|
|
<code id="tooltip-timestamp">...</code>
|
|
|
|
<div class="tooltip-title">Response time:</div>
|
|
|
|
<code id="tooltip-response-time">...</code>
|
|
|
|
<div class="tooltip-title">Conditions:</div>
|
|
|
|
<code id="tooltip-conditions">...</code>
|
|
|
|
<div id="tooltip-errors-container">
|
|
|
|
<div class="tooltip-title">Errors:</div>
|
|
|
|
<code id="tooltip-errors">...</code>
|
2019-09-17 02:29:06 +02:00
|
|
|
</div>
|
2019-09-12 22:15:42 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
|
|
|
|
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
2019-09-15 01:25:59 +02:00
|
|
|
|
2019-09-12 22:15:42 +02:00
|
|
|
<script>
|
2020-04-20 00:38:50 +02:00
|
|
|
let serviceStatuses = {};
|
|
|
|
let timerHandler = 0;
|
|
|
|
let userClickedStatus = false;
|
2019-09-12 22:15:42 +02:00
|
|
|
|
2020-04-20 00:38:50 +02:00
|
|
|
function showTooltip(serviceName, index, element) {
|
|
|
|
userClickedStatus = false;
|
|
|
|
clearTimeout(timerHandler);
|
|
|
|
let serviceResult = serviceStatuses[serviceName][index];
|
|
|
|
$("#tooltip-timestamp").text(prettifyTimestamp(serviceResult.timestamp));
|
|
|
|
$("#tooltip-response-time").text(parseInt(serviceResult.duration/1000000) + "ms");
|
|
|
|
// Populate the condition section
|
2019-12-28 18:19:52 +01:00
|
|
|
let conditions = "";
|
2020-04-20 00:38:50 +02:00
|
|
|
for (let i in serviceResult['condition-results']) {
|
|
|
|
let conditionResult = serviceResult['condition-results'][i];
|
|
|
|
conditions += (conditionResult.success ? "✓" : "X") + " ~ " + htmlEntities(conditionResult.condition) + "<br />";
|
2019-12-28 18:19:52 +01:00
|
|
|
}
|
2020-04-20 00:38:50 +02:00
|
|
|
$("#tooltip-conditions").html(conditions);
|
|
|
|
// Populate the error section only if there are errors
|
|
|
|
if (serviceResult.errors && serviceResult.errors.length > 0) {
|
2019-12-28 18:19:52 +01:00
|
|
|
let errors = "";
|
2020-04-20 00:38:50 +02:00
|
|
|
for (let i in serviceResult.errors) {
|
|
|
|
errors += "- " + htmlEntities(serviceResult.errors[i]) + "<br />";
|
2019-12-28 18:19:52 +01:00
|
|
|
}
|
2020-04-20 00:38:50 +02:00
|
|
|
$("#tooltip-errors").html(errors);
|
|
|
|
$("#tooltip-errors-container").show();
|
2019-12-28 18:19:52 +01:00
|
|
|
} else {
|
2020-04-20 00:38:50 +02:00
|
|
|
$("#tooltip-errors-container").hide();
|
|
|
|
}
|
|
|
|
// Position tooltip
|
|
|
|
$("#tooltip").css({top: "0px", left: "0px"}).show();
|
|
|
|
let targetTopPosition = element.getBoundingClientRect().y + 30;
|
|
|
|
let targetLeftPosition = element.getBoundingClientRect().x;
|
|
|
|
// Make adjustments if necessary
|
|
|
|
let tooltipBoundingClientRect = document.querySelector('#tooltip').getBoundingClientRect();
|
|
|
|
if (targetLeftPosition + window.scrollX + tooltipBoundingClientRect.width + 50 > document.body.getBoundingClientRect().width) {
|
|
|
|
targetLeftPosition = element.getBoundingClientRect().x - tooltipBoundingClientRect.width + element.getBoundingClientRect().width;
|
2020-08-22 04:07:46 +02:00
|
|
|
if (targetLeftPosition < 0) {
|
|
|
|
targetLeftPosition += -targetLeftPosition;
|
|
|
|
}
|
2020-04-20 00:38:50 +02:00
|
|
|
}
|
2020-08-25 20:27:13 +02:00
|
|
|
if (targetTopPosition + window.scrollY + tooltipBoundingClientRect.height + 50 > document.body.getBoundingClientRect().height && targetTopPosition >= 0) {
|
|
|
|
targetTopPosition = element.getBoundingClientRect().y - (tooltipBoundingClientRect.height + 10);
|
|
|
|
if (targetTopPosition < 0) {
|
|
|
|
targetTopPosition = element.getBoundingClientRect().y + 30;
|
|
|
|
}
|
2019-12-28 18:19:52 +01:00
|
|
|
}
|
2020-04-20 00:38:50 +02:00
|
|
|
$("#tooltip").css({top: targetTopPosition + "px", left: targetLeftPosition + "px"});
|
2019-12-28 18:19:52 +01:00
|
|
|
}
|
2020-04-20 00:38:50 +02:00
|
|
|
|
|
|
|
function fadeTooltip() {
|
|
|
|
if (!userClickedStatus) {
|
|
|
|
timerHandler = setTimeout(function () {
|
|
|
|
$("#tooltip").hide();
|
2020-05-01 23:22:30 +02:00
|
|
|
}, 500);
|
2020-04-20 00:38:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function createStatusBadge(serviceName, index, success) {
|
|
|
|
if (success) {
|
|
|
|
return "<span class='status badge badge-success' style='width: 5%' onmouseenter='showTooltip(\""+serviceName+"\", "+index+", this)' onmouseleave='fadeTooltip()' onclick='userClickedStatus = !userClickedStatus;'>✓</span>";
|
|
|
|
}
|
|
|
|
return "<span class='status badge badge-danger' style='width: 5%' onmouseenter='showTooltip(\""+serviceName+"\", "+index+", this)' onmouseleave='fadeTooltip()' onclick='userClickedStatus = !userClickedStatus;'>X</span>";
|
|
|
|
}
|
|
|
|
|
2020-03-10 23:34:32 +01:00
|
|
|
function refreshResults() {
|
2019-09-12 22:15:42 +02:00
|
|
|
$.getJSON("/api/v1/results", function (data) {
|
2020-08-15 22:42:47 +02:00
|
|
|
// Update the table only if there's a change
|
|
|
|
if (JSON.stringify(serviceStatuses) !== JSON.stringify(data)) {
|
|
|
|
serviceStatuses = data;
|
|
|
|
buildTable();
|
2019-09-12 22:15:42 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-08-15 22:42:47 +02:00
|
|
|
function buildTable() {
|
|
|
|
let output = "";
|
|
|
|
for (let serviceName in serviceStatuses) {
|
|
|
|
let serviceStatusOverTime = "";
|
|
|
|
let hostname = serviceStatuses[serviceName][serviceStatuses[serviceName].length-1].hostname
|
|
|
|
let minResponseTime = null;
|
|
|
|
let maxResponseTime = null;
|
|
|
|
let newestTimestamp = null;
|
|
|
|
let oldestTimestamp = null;
|
|
|
|
for (let key in serviceStatuses[serviceName]) {
|
|
|
|
let serviceResult = serviceStatuses[serviceName][key];
|
|
|
|
serviceStatusOverTime = createStatusBadge(serviceName, key, serviceResult.success) + serviceStatusOverTime;
|
|
|
|
const responseTime = parseInt(serviceResult.duration/1000000);
|
|
|
|
if (minResponseTime == null || minResponseTime > responseTime) {
|
|
|
|
minResponseTime = responseTime;
|
|
|
|
}
|
|
|
|
if (maxResponseTime == null || maxResponseTime < responseTime) {
|
|
|
|
maxResponseTime = responseTime;
|
|
|
|
}
|
|
|
|
const timestamp = new Date(serviceResult.timestamp);
|
|
|
|
if (newestTimestamp == null || newestTimestamp < timestamp) {
|
|
|
|
newestTimestamp = timestamp;
|
|
|
|
}
|
|
|
|
if (oldestTimestamp == null || oldestTimestamp > timestamp) {
|
|
|
|
oldestTimestamp = timestamp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
output += ""
|
|
|
|
+ "<div class='container py-3 border-left border-right border-top border-black'>"
|
|
|
|
+ " <div class='row mb-2'>"
|
2020-08-22 04:07:46 +02:00
|
|
|
+ " <div class='col-md-10'>"
|
2020-08-15 22:42:47 +02:00
|
|
|
+ " <span class='font-weight-bold'>" + serviceName + "</span> <span class='text-secondary font-weight-lighter'>- " + hostname + "</span>"
|
|
|
|
+ " </div>"
|
2020-08-22 04:07:46 +02:00
|
|
|
+ " <div class='col-md-2 text-right'>"
|
|
|
|
+ " <span class='font-weight-lighter status-min-max-ms'>" + (minResponseTime === maxResponseTime ? minResponseTime : (minResponseTime + "-" + maxResponseTime)) + "ms</span>"
|
2020-08-15 22:42:47 +02:00
|
|
|
+ " </div>"
|
|
|
|
+ " </div>"
|
|
|
|
+ " <div class='row'>"
|
|
|
|
+ " <div class='col-12 d-flex flex-row-reverse status-over-time'>"
|
|
|
|
+ " " + serviceStatusOverTime
|
|
|
|
+ " </div>"
|
|
|
|
+ " </div>"
|
|
|
|
+ " <div class='row status-time-ago'>"
|
|
|
|
+ " <div class='col-6'>"
|
|
|
|
+ " " + generatePrettyTimeAgo(oldestTimestamp)
|
|
|
|
+ " </div>"
|
|
|
|
+ " <div class='col-6 text-right'>"
|
|
|
|
+ " " + generatePrettyTimeAgo(newestTimestamp)
|
|
|
|
+ " </div>"
|
|
|
|
+ " </div>"
|
|
|
|
+ "</div>";
|
|
|
|
}
|
|
|
|
$("#results").html(output);
|
|
|
|
}
|
|
|
|
|
2020-04-08 00:23:26 +02:00
|
|
|
function prettifyTimestamp(timestamp) {
|
|
|
|
let date = new Date(timestamp);
|
|
|
|
let YYYY = date.getFullYear();
|
|
|
|
let MM = ((date.getMonth()+1)<10?"0":"")+""+(date.getMonth()+1);
|
|
|
|
let DD = ((date.getDate())<10?"0":"")+""+(date.getDate());
|
|
|
|
let hh = ((date.getHours())<10?"0":"")+""+(date.getHours());
|
|
|
|
let mm = ((date.getMinutes())<10?"0":"")+""+(date.getMinutes());
|
|
|
|
let ss = ((date.getSeconds())<10?"0":"")+""+(date.getSeconds());
|
2020-08-22 04:07:46 +02:00
|
|
|
return YYYY + "-" + MM + "-" + DD + " " + hh + ":" + mm + ":" + ss;
|
2020-04-08 00:23:26 +02:00
|
|
|
}
|
|
|
|
|
2020-04-20 00:38:50 +02:00
|
|
|
function generatePrettyTimeAgo(t) {
|
|
|
|
let differenceInMs = new Date().getTime() - new Date(t).getTime();
|
|
|
|
if (differenceInMs > 3600000) {
|
|
|
|
let hours = (differenceInMs/3600000).toFixed(0);
|
|
|
|
return hours + " hour" + (hours !== "1" ? "s" : "") + " ago";
|
|
|
|
}
|
|
|
|
if (differenceInMs > 60000) {
|
|
|
|
let minutes = (differenceInMs/60000).toFixed(0);
|
|
|
|
return minutes + " minute" + (minutes !== "1" ? "s" : "") + " ago";
|
|
|
|
}
|
|
|
|
return (differenceInMs/1000).toFixed(0) + " seconds ago";
|
|
|
|
}
|
|
|
|
|
2020-04-15 01:20:00 +02:00
|
|
|
function htmlEntities(s) {
|
|
|
|
return String(s)
|
|
|
|
.replace(/&/g, '&')
|
|
|
|
.replace(/</g, '<')
|
|
|
|
.replace(/>/g, '>')
|
|
|
|
.replace(/"/g, '"')
|
|
|
|
.replace(/'/g, ''');
|
|
|
|
}
|
|
|
|
|
2020-03-10 23:34:32 +01:00
|
|
|
refreshResults();
|
2019-09-12 22:15:42 +02:00
|
|
|
setInterval(function() {
|
2020-03-10 23:34:32 +01:00
|
|
|
refreshResults();
|
2020-04-20 00:38:50 +02:00
|
|
|
}, 30000);
|
2019-09-12 22:15:42 +02:00
|
|
|
</script>
|
|
|
|
</body>
|
2019-10-06 04:47:09 +02:00
|
|
|
</html>
|