Added metrics to Etherpad

This commit is contained in:
SamTv12345 2024-09-10 15:09:44 +02:00
parent 4891243c27
commit 0722a7ed7c
4 changed files with 40 additions and 3 deletions

View file

@ -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 = ()=> {
<li><NavLink to={"/pads"}><NotepadText/><Trans
i18nKey="ep_admin_pads:ep_adminpads2_manage-pads"/></NavLink></li>
<li><NavLink to={"/shout"}><PhoneCall/>Communication</NavLink></li>
<li><NavLink to={"/metrics"}><Box/>Metrics</NavLink></li>
</ul>
</div>
</div>

View file

@ -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(
<><Route element={<App/>}>
@ -22,6 +23,7 @@ const router = createBrowserRouter(createRoutesFromElements(
<Route path="/help" element={<HelpPage/>}/>
<Route path="/pads" element={<PadPage/>}/>
<Route path="/shout" element={<ShoutPage/>}/>
<Route path="metrics" element={<MetricsPage/>}/>
</Route><Route path="/login">
<Route index element={<LoginScreen/>}/>
</Route></>

View file

@ -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 <>
<h1>Metrics</h1>
</>
}

View file

@ -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
})
})
});
};