Skip to content

Commit

Permalink
Added metrics to Etherpad
Browse files Browse the repository at this point in the history
  • Loading branch information
SamTv12345 committed Sep 10, 2024
1 parent 4891243 commit 0722a7e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
3 changes: 2 additions & 1 deletion admin/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ()=> {
Expand Down Expand Up @@ -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>
Expand Down
2 changes: 2 additions & 0 deletions admin/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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/>}>
Expand All @@ -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></>
Expand Down
22 changes: 22 additions & 0 deletions admin/src/pages/MetricsPage.tsx
Original file line number Diff line number Diff line change
@@ -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>

</>
}
16 changes: 14 additions & 2 deletions src/node/hooks/express/adminsettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');

Expand Down Expand Up @@ -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
})
})

});
};

Expand Down

0 comments on commit 0722a7e

Please sign in to comment.