add realtime statistics!!!
Some checks failed
Deploy App / docker (ubuntu-latest) (push) Has been cancelled

This commit is contained in:
Lee
2024-04-18 01:21:38 +01:00
parent f5203f9742
commit defdcccdb6
14 changed files with 143 additions and 9 deletions

View File

@ -8,7 +8,7 @@ export default function Container({
return (
<div className="z-[9999] m-auto flex h-screen min-h-full flex-col items-center opacity-90 w-full xs:max-w-[1200px]">
<NavBar />
<div className="w-full flex m-4 justify-center">{children}</div>
<div className="w-full h-full flex m-4 justify-center">{children}</div>
</div>
);
}

View File

@ -3,7 +3,10 @@ import { IconProps } from "./icon-props";
export function MoonIcon({ size = 24, color = "#fff" }: IconProps): JSX.Element {
return (
<svg xmlns="http://www.w3.org/2000/svg" width={size} height={size} fill={color} viewBox="0 -960 960 960">
<path d="M480-120q-150 0-255-105T120-480q0-150 105-255t255-105q14 0 27.5 1t26.5 3q-41 29-65.5 75.5T444-660q0 90 63 153t153 63q55 0 101-24.5t75-65.5q2 13 3 26.5t1 27.5q0 150-105 255T480-120Zm0-80q88 0 158-48.5T740-375q-20 5-40 8t-40 3q-123 0-209.5-86.5T364-660q0-20 3-40t8-40q-78 32-126.5 102T200-480q0 116 82 198t198 82Zm-10-270Z" />
<path
xmlns="http://www.w3.org/2000/svg"
d="M480-120q-150 0-255-105T120-480q0-150 105-255t255-105q8 0 17 .5t23 1.5q-36 32-56 79t-20 99q0 90 63 153t153 63q52 0 99-18.5t79-51.5q1 12 1.5 19.5t.5 14.5q0 150-105 255T480-120Zm0-60q109 0 190-67.5T771-406q-25 11-53.667 16.5Q688.667-384 660-384q-114.689 0-195.345-80.655Q384-545.311 384-660q0-24 5-51.5t18-62.5q-98 27-162.5 109.5T180-480q0 125 87.5 212.5T480-180Zm-4-297Z"
/>
</svg>
);
}

View File

@ -0,0 +1,12 @@
import { IconProps } from "./icon-props";
export function StorageIcon({ size = 24, color = "#fff" }: IconProps): JSX.Element {
return (
<svg xmlns="http://www.w3.org/2000/svg" width={size} height={size} fill={color} viewBox="0 -960 960 960">
<path
xmlns="http://www.w3.org/2000/svg"
d="M120-160v-148h720v148H120Zm60-38h72v-72h-72v72Zm-60-454v-148h720v148H120Zm60-38h72v-72h-72v72Zm-60 284v-148h720v148H120Zm60-38h72v-72h-72v72Z"
/>
</svg>
);
}

View File

@ -0,0 +1,20 @@
import { ReactElement } from "react";
import CountUp from "react-countup";
type StatProps = {
title: string;
value: number;
icon: ReactElement;
};
export function Stat({ title, value, icon }: StatProps): ReactElement {
return (
<div className="bg-secondary p-2 rounded-lg flex divide-x justify-center items-center text-center w-fit">
<div className="pr-2">{icon}</div>
<div className="pl-2">
<p>{title}</p>
<CountUp start={0} end={value} duration={0.5} preserveValue />
</div>
</div>
);
}

View File

@ -0,0 +1,35 @@
"use client";
import { ReactElement } from "react";
import { StorageIcon } from "@/app/components/icon/storage-icon";
import { Stat } from "@/app/components/stat";
import useWebSocket from "react-use-websocket";
type Stat = {
id: string;
displayName: string;
icon: ReactElement;
};
const stats: Stat[] = [
{
id: "totalRequests",
displayName: "Total Requests",
icon: <StorageIcon />,
},
];
export function Stats(): ReactElement {
const { lastMessage, readyState } = useWebSocket("https://api.mcutils.xyz/websocket/metrics");
const metrics = lastMessage !== null ? JSON.parse(lastMessage.data).metrics : undefined;
return (
<>
{stats.map((stat, index) => {
const value = metrics ? metrics[stat.id] : "???";
return <Stat key={index} title={stat.displayName} value={value} icon={stat.icon} />;
})}
</>
);
}