2022-07-08 12:50:15 +00:00
|
|
|
<script>
|
2022-07-08 15:17:17 +00:00
|
|
|
import { onMount } from 'svelte';
|
2022-07-11 09:20:44 +00:00
|
|
|
import TileRawValue from './tile-rawvalue.svelte';
|
2022-07-11 09:32:28 +00:00
|
|
|
import Tiles from './tiles.svelte';
|
2022-07-11 10:07:05 +00:00
|
|
|
import Settings from './settings.svelte';
|
2022-07-08 15:17:17 +00:00
|
|
|
|
2022-07-11 09:20:44 +00:00
|
|
|
let lastUpdated = new Date();
|
|
|
|
let lastUpdatedFormatted = '';
|
|
|
|
let services = {};
|
2022-07-11 09:32:28 +00:00
|
|
|
let servicesUp = {};
|
|
|
|
let servicesDown = {};
|
2022-07-11 11:15:39 +00:00
|
|
|
let servicesUnknown = {};
|
2022-07-11 12:21:57 +00:00
|
|
|
let servicesInCluster = {};
|
|
|
|
let servicesInClusterUnknown = {};
|
|
|
|
const clusters = JSON.parse('__CLUSTERS__');
|
|
|
|
const clusterKeys = clusters ? Object.keys(clusters) : false;
|
|
|
|
let currentClusterIndex = -1;
|
2022-07-11 09:20:44 +00:00
|
|
|
let loading = true;
|
2022-07-11 12:21:57 +00:00
|
|
|
let lock = false;
|
2022-07-11 09:20:44 +00:00
|
|
|
|
|
|
|
onMount(() => {
|
|
|
|
const ws = new WebSocket('ws://__SERVER__/statusdashboard/socket');
|
|
|
|
|
|
|
|
ws.onmessage = async evt => {
|
|
|
|
const data = JSON.parse(evt.data || '""');
|
|
|
|
|
|
|
|
switch (data.cmd) {
|
|
|
|
case 'time':
|
|
|
|
lastUpdated = new Date(data.time);
|
|
|
|
lastUpdatedFormatted = lastUpdated.toLocaleTimeString('en-GB', {
|
|
|
|
timeStyle: 'short',
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'data':
|
2022-07-11 12:21:57 +00:00
|
|
|
while (lock) {}
|
|
|
|
|
2022-07-11 09:20:44 +00:00
|
|
|
services = data.data;
|
2022-07-11 09:32:28 +00:00
|
|
|
const ids = Object.keys(services);
|
|
|
|
|
|
|
|
for (const id of ids) {
|
|
|
|
const service = services[id];
|
2022-07-11 11:15:39 +00:00
|
|
|
if (!service.lastBeat || !service.lastBeat.date) {
|
|
|
|
servicesUnknown = {
|
|
|
|
...servicesUnknown,
|
|
|
|
[id]: service,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else if (service.lastBeat.down) {
|
2022-07-11 09:32:28 +00:00
|
|
|
servicesDown = {
|
|
|
|
...servicesDown,
|
|
|
|
[id]: service,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
servicesUp = {
|
|
|
|
...servicesUp,
|
|
|
|
[id]: service,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-11 09:20:44 +00:00
|
|
|
loading = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2022-07-11 12:21:57 +00:00
|
|
|
|
|
|
|
$: if (clusterKeys?.length && !loading) {
|
|
|
|
function nextCluster() {
|
|
|
|
lock = true;
|
|
|
|
currentClusterIndex++;
|
|
|
|
|
|
|
|
if (currentClusterIndex >= clusterKeys.length) {
|
|
|
|
currentClusterIndex = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const inClusterTemp = {};
|
|
|
|
const inClusterTempUnknown = {};
|
|
|
|
const currentClusterKey = clusterKeys[currentClusterIndex];
|
|
|
|
|
|
|
|
for (const [ id, s ] of Object.entries(services)) {
|
|
|
|
if (s.cluster === currentClusterKey) {
|
|
|
|
if (!s.lastBeat || !s.lastBeat.date) {
|
|
|
|
inClusterTempUnknown[id] = s;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
inClusterTemp[id] = s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
servicesInCluster = inClusterTemp;
|
|
|
|
servicesInClusterUnknown = inClusterTempUnknown;
|
|
|
|
lock = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nextCluster();
|
|
|
|
setInterval(() => nextCluster, 10_000);
|
|
|
|
}
|
2022-07-08 12:50:15 +00:00
|
|
|
</script>
|
|
|
|
|
2022-07-11 10:07:05 +00:00
|
|
|
<Settings />
|
|
|
|
|
2022-07-08 15:17:17 +00:00
|
|
|
<div class="center">
|
|
|
|
<div class="ratio">
|
2022-07-11 09:20:44 +00:00
|
|
|
<div class="tiles">
|
|
|
|
<TileRawValue title="Last updated" value={lastUpdatedFormatted} />
|
2022-07-08 15:17:17 +00:00
|
|
|
|
2022-07-11 09:20:44 +00:00
|
|
|
{#if !loading}
|
2022-07-11 11:15:39 +00:00
|
|
|
<Tiles services={servicesDown} color="red" value="down" />
|
2022-07-11 12:21:57 +00:00
|
|
|
|
|
|
|
{#if !clusterKeys?.length}
|
|
|
|
<Tiles services={servicesUp} color="green" value="up" />
|
|
|
|
<Tiles services={servicesUnknown} color="grey" value="no data" />
|
|
|
|
{:else}
|
|
|
|
<Tiles services={servicesInCluster} color="green" value="up" />
|
|
|
|
<Tiles services={servicesInClusterUnknown} color="grey" value="no data" />
|
|
|
|
{/if}
|
2022-07-11 09:20:44 +00:00
|
|
|
{:else}
|
|
|
|
loading
|
|
|
|
{/if}
|
|
|
|
</div>
|
2022-07-08 15:17:17 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-07-08 12:50:15 +00:00
|
|
|
|
|
|
|
<style>
|
2022-07-08 15:17:17 +00:00
|
|
|
.center {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
width: 100vw;
|
|
|
|
height: 100vh;
|
|
|
|
}
|
|
|
|
|
|
|
|
.ratio {
|
|
|
|
height: 56.25vw;
|
|
|
|
left: 50%;
|
|
|
|
max-height: 100vh;
|
|
|
|
max-width: 177.77778vh;
|
|
|
|
position: absolute;
|
|
|
|
top: 50%;
|
|
|
|
transform: translate(-50%,-50%);
|
|
|
|
width: 100vw;
|
2022-07-08 12:50:15 +00:00
|
|
|
}
|
2022-07-11 09:20:44 +00:00
|
|
|
|
|
|
|
.tiles {
|
|
|
|
margin: 1rem;
|
|
|
|
display: grid;
|
|
|
|
grid-template-columns: repeat(var(--cols), 1fr);
|
|
|
|
grid-template-rows: repeat(var(--rows), 1fr);
|
|
|
|
gap: 1rem;
|
|
|
|
justify-items: stretch;
|
|
|
|
}
|
2022-07-08 12:50:15 +00:00
|
|
|
</style>
|