From 145bbf9b62a5fca59733e343b76b3472317d8a7f Mon Sep 17 00:00:00 2001 From: Jake Fulmine Date: Sat, 22 Oct 2022 17:24:29 +0200 Subject: [PATCH] fix(dashboard): improve shard status page --- dashboard/src/lib/shard.svelte | 15 ++++--- dashboard/src/pages/status.svelte | 69 +++++++++++++++++++++---------- 2 files changed, 57 insertions(+), 27 deletions(-) diff --git a/dashboard/src/lib/shard.svelte b/dashboard/src/lib/shard.svelte index 201016a1..cbcee67f 100644 --- a/dashboard/src/lib/shard.svelte +++ b/dashboard/src/lib/shard.svelte @@ -7,14 +7,14 @@ ping:0, disconnection_count:0, last_connection:0, - last_heartbeat:0. + last_heartbeat:0, + heartbeat_minutes_ago:0 }; let color = "background-color: #fff"; // shard is down - // todo: check if last heartbeat is really recent, since database up/down status can get out of sync - if (shard.status != "up") color = "background-color: #000;"; + if (shard.status != "up" || shard.heartbeat_minutes_ago > 5) color = "background-color: #000;"; // shard latency is < 250ms: OK! else if (shard.ping < 300) color = "background-color: #00cc00;"; // shard latency is 250ms < ping < 600ms: slow, but OK @@ -35,9 +35,12 @@ Status: { shard.status }
Latency: { shard.ping }ms
Disconnection count: { shard.disconnection_count }
- Last connection: { shard.last_connection }
- Last heartbeat: { shard.last_heartbeat }
-
+ Last connection: { shard.last_connection } UTC
+ Last heartbeat: { shard.last_heartbeat } UTC + {#if shard.heartbeat_minutes_ago > 5} + (over {Math.floor(shard.heartbeat_minutes_ago)} minutes ago) + {/if} +

diff --git a/dashboard/src/pages/status.svelte b/dashboard/src/pages/status.svelte index ed23ee15..32fd5938 100644 --- a/dashboard/src/pages/status.svelte +++ b/dashboard/src/pages/status.svelte @@ -16,7 +16,8 @@ ping:"", disconnection_count:0, last_connection:0, - last_heartbeat:0. + last_heartbeat:0, + heartbeat_minutes_ago:0 }; foundShard = null; @@ -29,7 +30,8 @@ let pings = 0; data = data.map(shard => { pings += shard.ping; - shard.last_connection = new Date(Number(shard.last_connection) * 1000).toUTCString().match(/([0-9][0-9]:[0-9][0-9]:[0-9][0-9])/)?.shift() + shard.heartbeat_minutes_ago = heartbeatMinutesAgo(shard); + shard.last_connection = new Date(Number(shard.last_connection) * 1000).toUTCString().match(/([0-9][0-9]:[0-9][0-9]:[0-9][0-9])/)?.shift() shard.last_heartbeat = new Date(Number(shard.last_heartbeat) * 1000).toUTCString().match(/([0-9][0-9]:[0-9][0-9]:[0-9][0-9])/)?.shift() return shard; }); @@ -64,7 +66,7 @@ shardInfoMsg = ""; return; }; - var match = findShardInput.match(/https:\/\/[\w+]?discord[app]?.com\/channels\/(\d+)\/\d+\/\d+/); + var match = findShardInput.match(/https:\/\/(?:[\w]*\.)?discord(?:app)?\.com\/channels\/(\d+)\/\d+\/\d+/); if (match != null) { console.log("match", match) foundShard = shards[Number(getShardID(match[1], shards.length))]; @@ -89,6 +91,14 @@ } }; + function heartbeatMinutesAgo(shard) { + // difference in milliseconds + const msDifference = Math.abs((Number(new Date(Number(shard.last_heartbeat) * 1000)) - Date.now())); + // convert to minutes + const minuteDifference = msDifference / (60 * 1000); + + return minuteDifference; + } @@ -107,29 +117,46 @@
- { shards.length } shards ({ shards.filter(x => x.status == "up").length } up)
- Average latency: { pingAverage }ms -

- All times in UTC. More statistics available at https://stats.pluralkit.me -

-
- Find my shard -
- Enter a server ID or a message link to find the shard currently assigned to your server: -
- -

- { shardInfoMsg } + + + { shards.length } shards ({ shards.filter(x => x.status == "up").length } up) + + + Average latency: { pingAverage }ms + + + More statistics available at https://stats.pluralkit.me + + +
+

Find my shard

+

Enter a server ID or a message link to find the shard currently assigned to your server

+ + + {#if shardInfoMsg || foundShard} + + + + {#if shardInfoMsg} + {shardInfoMsg} + {/if} + {#if foundShard} + Your shard is: Shard { foundShard.id } + {/if} + + + {#if valid} -

Your shard is: Shard { foundShard.id }

-
+ Status: { foundShard.status }
Latency: { foundShard.ping }ms
Disconnection count: { foundShard.disconnection_count }
- Last connection: { foundShard.last_connection }
- Last heartbeat: { foundShard.last_heartbeat }
+ Last connection: { foundShard.last_connection } UTC
+ Last heartbeat: { foundShard.last_heartbeat } UTC
+
+ {/if} +
{/if} -