From efcb17ca981309e65c34dfcfe3d3aadbfa09f2b9 Mon Sep 17 00:00:00 2001 From: theMackabu Date: Tue, 9 Jul 2024 00:01:38 -0700 Subject: [PATCH] implement charts --- src/webui/src/components/react/servers.tsx | 63 ++++++++++++++++++---- src/webui/src/components/react/status.tsx | 59 ++++++++++++-------- 2 files changed, 88 insertions(+), 34 deletions(-) diff --git a/src/webui/src/components/react/servers.tsx b/src/webui/src/components/react/servers.tsx index e65981c..286cb30 100644 --- a/src/webui/src/components/react/servers.tsx +++ b/src/webui/src/components/react/servers.tsx @@ -5,14 +5,16 @@ import Header from '@/components/react/header'; import { version } from '../../../package.json'; import { useArray, classNames, isVersionTooFar, startDuration } from '@/helpers'; -const getStatus = (remote: string, status: string) => { +const getStatus = (remote: string, status: string): string => { const badge = { updated: 'bg-emerald-700/40 text-emerald-400', behind: 'bg-gray-700/40 text-gray-400', critical: 'bg-red-700/40 text-red-400' }; - if (isVersionTooFar(version, remote.slice(1))) { + if (remote == 'v0.0.0') { + return badge['behind']; + } else if (isVersionTooFar(version, remote.slice(1))) { return badge['behind']; } else if (remote == `v${version}`) { return badge['updated']; @@ -21,6 +23,45 @@ const getStatus = (remote: string, status: string) => { } }; +const skeleton = { + os: { name: '' }, + version: { + pkg: 'v0.0.0', + hash: 'none', + build_date: 'none', + target: '' + }, + daemon: { + pid: 'none', + running: false, + uptime: 0, + process_count: 'none' + } +}; + +const getServerIcon = (base: string, distro: string): string => { + const distroList = [ + 'Alpine', + 'Arch', + 'Amazon', + 'Macos', + 'Linux', + 'Fedora', + 'Debian', + 'CentOS', + 'NixOS', + 'FreeBSD', + 'OracleLinux', + 'Pop', + 'Raspbian', + 'Redhat', + 'Ubuntu' + ]; + + const isDistroKnown = distroList.includes(distro); + return `${base}/distro/${isDistroKnown ? distro : 'Unknown'}.svg`; +}; + const Index = (props: { base: string }) => { const items = useArray([]); @@ -38,8 +79,11 @@ const Index = (props: { base: string }) => { try { const servers = await api.get(props.base + '/daemon/servers').json(); await servers.forEach(async (name) => { - const metrics = await api.get(props.base + `/remote/${name}/metrics`).json(); - items.push({ ...metrics, name }); + api + .get(props.base + `/remote/${name}/metrics`) + .json() + .then((metrics) => items.push({ ...metrics, name })) + .catch(() => items.push({ ...skeleton, name })); }); } catch {} } @@ -108,10 +152,7 @@ const Index = (props: { base: string }) => { onClick={() => (window.location.href = props.base + '/status/' + server.name)}>
- +
{server.name == 'local' ? 'Internal' : server.name}
@@ -128,7 +169,7 @@ const Index = (props: { base: string }) => {
- {server.version.target}_{server.version.build_date} + {server.version.target} {server.version.build_date}
@@ -139,7 +180,7 @@ const Index = (props: { base: string }) => { {server.daemon.process_count}
- {startDuration(server.daemon.uptime, false)} + {server.daemon.uptime == 0 ? 'none' : startDuration(server.daemon.uptime, false)}
@@ -147,7 +188,7 @@ const Index = (props: { base: string }) => {
- {startDuration(server.daemon.uptime, false)} + {server.daemon.uptime == 0 ? 'none' : startDuration(server.daemon.uptime, false)} ))} diff --git a/src/webui/src/components/react/status.tsx b/src/webui/src/components/react/status.tsx index 84541b6..6b8ae4f 100644 --- a/src/webui/src/components/react/status.tsx +++ b/src/webui/src/components/react/status.tsx @@ -23,13 +23,14 @@ const Status = (props: { name: string; base: string }) => { const memoryUsage = useArray([], bufferLength); const cpuPercentage = useArray([], bufferLength); + const [item, setItem] = useState(); const [loaded, setLoaded] = useState(false); const [live, setLive] = useState(null); const options = { responsive: true, maintainAspectRatio: false, - animation: { duration: 0.5 }, + animation: { duration: 0 }, layout: { padding: { left: 0, @@ -121,6 +122,8 @@ const Status = (props: { name: string; base: string }) => { source.onmessage = (event) => { const data = JSON.parse(event.data); + setItem(data); + memoryUsage.pushMax(data.raw.memory_usage.rss); cpuPercentage.pushMax(data.raw.cpu_percent + 1); @@ -149,47 +152,57 @@ const Status = (props: { name: string; base: string }) => { }; }, []); - const stats = [ - { name: 'Status', stat: 'Online' }, - { name: 'Proccess', stat: '3' }, - { name: 'Errors', stat: '10' }, - { name: 'Crashes', stat: '2' } - ]; - if (!loaded) { return ; } else { + const stats = [ + { name: 'Uptime', stat: startDuration(item.daemon.uptime, false) }, + { name: 'Count', stat: item.daemon.process_count }, + { name: 'Version', stat: item.version.pkg }, + { name: 'Process Id', stat: item.daemon.pid }, + { name: 'Build date', stat: item.version.build_date }, + { name: 'Hash', stat: item.version.hash.slice(0, 18) }, + { name: 'Platform', stat: `${item.os.name} ${item.os.version} (${item.os.arch})` }, + { name: 'Daemon', stat: item.daemon.daemon_type } + ]; + return ( -

Overview

-
- {stats.map((item: any) => ( -
-
{item.name}
-
{item.stat}
-
- ))} -
-

Metrics

-
-
+
+ + + {props.name != 'local' ? props.name : 'Internal'} + +
+
+
CPU Usage
{cpuPercentage.value.slice(-1)[0].toFixed(2)} %
-
+
-
+
Memory Usage
{bytesToSize(memoryUsage.value.slice(-1)[0], 2)}
-
+
+
+ {stats.map((item: any) => ( +
+
{item.name}
+
{item.stat}
+
+ ))} +
); } -- GitLab