From 0722a7ed7ce6b190eec04f764a8f3cdb4ab0592d Mon Sep 17 00:00:00 2001 From: SamTv12345 Date: Tue, 10 Sep 2024 15:09:44 +0200 Subject: [PATCH] Added metrics to Etherpad --- admin/src/App.tsx | 3 ++- admin/src/main.tsx | 2 ++ admin/src/pages/MetricsPage.tsx | 22 ++++++++++++++++++++++ src/node/hooks/express/adminsettings.ts | 16 ++++++++++++++-- 4 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 admin/src/pages/MetricsPage.tsx diff --git a/admin/src/App.tsx b/admin/src/App.tsx index b3238ef9a..f2e23805c 100644 --- a/admin/src/App.tsx +++ b/admin/src/App.tsx @@ -6,7 +6,7 @@ import {NavLink, Outlet, useNavigate} from "react-router-dom"; import {useStore} from "./store/store.ts"; import {LoadingScreen} from "./utils/LoadingScreen.tsx"; import {Trans, useTranslation} from "react-i18next"; -import {Cable, Construction, Crown, NotepadText, Wrench, PhoneCall} from "lucide-react"; +import {Cable, Construction, Crown, NotepadText, Wrench, PhoneCall, Box} from "lucide-react"; const WS_URL = import.meta.env.DEV? 'http://localhost:9001' : '' export const App = ()=> { @@ -100,6 +100,7 @@ export const App = ()=> {
  • Communication
  • +
  • Metrics
  • diff --git a/admin/src/main.tsx b/admin/src/main.tsx index 5efc26de6..68b5b0853 100644 --- a/admin/src/main.tsx +++ b/admin/src/main.tsx @@ -13,6 +13,7 @@ import i18n from "./localization/i18n.ts"; import {PadPage} from "./pages/PadPage.tsx"; import {ToastDialog} from "./utils/Toast.tsx"; import {ShoutPage} from "./pages/ShoutPage.tsx"; +import {MetricsPage} from "./pages/MetricsPage.tsx"; const router = createBrowserRouter(createRoutesFromElements( <>}> @@ -22,6 +23,7 @@ const router = createBrowserRouter(createRoutesFromElements( }/> }/> }/> + }/> }/> diff --git a/admin/src/pages/MetricsPage.tsx b/admin/src/pages/MetricsPage.tsx new file mode 100644 index 000000000..5a66768bb --- /dev/null +++ b/admin/src/pages/MetricsPage.tsx @@ -0,0 +1,22 @@ +import {useEffect} from "react"; +import {useStore} from "../store/store.ts"; + +export const MetricsPage = ()=> { + const socket = useStore(state=>state.settingsSocket) + + useEffect(() => { + if (socket === undefined) return + + socket?.on('metrics:result', (d)=>{ + console.log(d) + }) + + socket?.emit('metrics') + }, [socket]); + + + return <> +

    Metrics

    + + +} diff --git a/src/node/hooks/express/adminsettings.ts b/src/node/hooks/express/adminsettings.ts index 63d901f21..e464c706a 100644 --- a/src/node/hooks/express/adminsettings.ts +++ b/src/node/hooks/express/adminsettings.ts @@ -4,7 +4,7 @@ import {PadQueryResult, PadSearchQuery} from "../../types/PadSearchQuery"; import {PadType} from "../../types/PadType"; import log4js from 'log4js'; - +import {freemem, totalmem, loadavg} from 'node:os' const eejs = require('../../eejs'); const fsp = require('fs').promises; const hooks = require('../../../static/js/pluginfw/hooks'); @@ -14,7 +14,6 @@ const UpdateCheck = require('../../utils/UpdateCheck'); const padManager = require('../../db/PadManager'); const api = require('../../db/API'); - const queryPadLimit = 12; const logger = log4js.getLogger('adminSettings'); @@ -259,6 +258,19 @@ exports.socketio = (hookName: string, {io}: any) => { await hooks.aCallAll('loadSettings', {settings}); await hooks.aCallAll('restartServer'); }); + + + socket.on('metrics', async()=>{ + + const memory = process.memoryUsage() + const freememTotal = freemem() + const totalAvailableMem = totalmem() + const cpu = loadavg() + socket.emit('metrics:response',{ + cpu, memory,freememTotal, totalAvailableMem + }) + }) + }); };