diff --git a/resources/scripts/components/server/ServerConsole.tsx b/resources/scripts/components/server/ServerConsole.tsx index a93550d7e..aa6bf4bf9 100644 --- a/resources/scripts/components/server/ServerConsole.tsx +++ b/resources/scripts/components/server/ServerConsole.tsx @@ -1,15 +1,54 @@ -import React from 'react'; -import Console from '@/components/server/Console'; +import React, { lazy, useEffect, useState } from 'react'; import { ServerContext } from '@/state/server'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faServer } from '@fortawesome/free-solid-svg-icons/faServer'; import { faCircle } from '@fortawesome/free-solid-svg-icons/faCircle'; import classNames from 'classnames'; +import styled from 'styled-components'; +import { faMemory } from '@fortawesome/free-solid-svg-icons/faMemory'; +import { faMicrochip } from '@fortawesome/free-solid-svg-icons/faMicrochip'; +import { bytesToHuman } from '@/helpers'; +import Spinner from '@/components/elements/Spinner'; + +const GreyBox = styled.div` + ${tw`mt-4 shadow-md bg-neutral-700 rounded p-3 flex text-xs`} +`; + +const ChunkedConsole = lazy(() => import('@/components/server/Console')); export default () => { + const [ memory, setMemory ] = useState(0); + const [ cpu, setCpu ] = useState(0); + const server = ServerContext.useStoreState(state => state.server.data!); const status = ServerContext.useStoreState(state => state.status.value); + const { connected, instance } = ServerContext.useStoreState(state => state.socket); + + const statsListener = (data: string) => { + let stats: any = {}; + try { + stats = JSON.parse(data); + } catch (e) { + return; + } + + setMemory(stats.memory_bytes); + setCpu(stats.cpu_absolute); + }; + + useEffect(() => { + if (!connected || !instance) { + return; + } + + instance.addListener('stats', statsListener); + + return () => { + instance.removeListener('stats', statsListener); + }; + }, [ connected ]); + return (
@@ -23,20 +62,51 @@ export default () => {

 {status}

+

+ +  {bytesToHuman(memory)} + / {server.limits.memory} MB +

+

+ +  {cpu.toFixed(2)} % +

+ + + + + -
- -
+ + + + } + > +
+ +
+
); };