feat: disable stats endpoint if enableMetrics is false

This commit is contained in:
SamTV12345 2025-07-27 21:54:24 +02:00 committed by SamTV12345
parent 45a906e19d
commit 40884fa96b
11 changed files with 462 additions and 647 deletions

View file

@ -9,22 +9,29 @@ export const ShoutPage = ()=>{
const [message, setMessage] = useState<string>("");
const [sticky, setSticky] = useState<boolean>(false);
const socket = useStore(state => state.settingsSocket);
const pluginSocket = useStore(state => state.pluginsSocket);
const [shouts, setShouts] = useState<ShoutType[]>([]);
useEffect(() => {
fetch('/stats')
.then(response => response.json())
.then(data => setTotalUsers(data.totalUsers));
}, []);
useEffect(() => {
if(socket) {
if(socket && pluginSocket) {
console.log('Socket connected', socket.id);
socket.on('shout', (shout) => {
setShouts([...shouts, shout])
})
pluginSocket.on('results:stats', (statData) => {
console.log('Shoutdata', statData);
setTotalUsers(statData.totalUsers);
})
}
}, [socket, shouts])
}, [socket, shouts, pluginSocket])
useEffect(() => {
if (pluginSocket) {
pluginSocket.emit('getStats', {});
}
}, [pluginSocket]);
const sendMessage = () => {
socket?.emit('shout', {

View file

@ -28,10 +28,6 @@ export default defineConfig({
'/admin-auth/': {
target: 'http://localhost:9001',
changeOrigin: true,
},
'/stats': {
target: 'http://localhost:9001',
changeOrigin: true,
}
}
}

View file

@ -6,5 +6,8 @@
"docs:dev": "vitepress dev",
"docs:build": "vitepress build",
"docs:preview": "vitepress preview"
},
"peerDependencies": {
"search-insights": "^2.17.3"
}
}

1036
pnpm-lock.yaml generated

File diff suppressed because it is too large Load diff

View file

@ -171,6 +171,14 @@
*/
"showSettingsInAdminPage": "${SHOW_SETTINGS_IN_ADMIN_PAGE:true}",
/*
* Enable/disable the metrics endpoint.
*
* This is used by the monitoring plugins to collect metrics about Etherpad.
* If you do not use any monitoring plugins, you can disable this.
*/
"enableMetrics": ${ENABLE_METRICS:true},
/*
* Settings for cleanup of pads
*/

View file

@ -162,6 +162,14 @@
*/
"showSettingsInAdminPage": true,
/*
* Enable/disable the metrics endpoint.
*
* This is used by the monitoring plugins to collect metrics about Etherpad.
* If you do not use any monitoring plugins, you can disable this.
*/
"enableMetrics": ${ENABLE_METRICS:true},
/*
* Settings for cleanup of pads
*/

View file

@ -234,7 +234,7 @@ exports.restartServer = async () => {
// Give plugins an opportunity to install handlers/middleware before the express-session
// middleware. This allows plugins to avoid creating an express-session record in the database
// when it is not needed (e.g., public static content).
await hooks.aCallAll('expressPreSession', {app});
await hooks.aCallAll('expressPreSession', {app, settings});
app.use(exports.sessionMiddleware);
app.use(webaccess.checkAccess);

View file

@ -39,6 +39,11 @@ exports.socketio = (hookName:string, args:ArgsExpressType, cb:Function) => {
})
}
socket.on('getStats', ()=>{
console.log("Getting stats for admin plugins");
socket.emit('results:stats', require('../../stats').toJSON());
})
socket.on('getInstalled', async (query: string) => {
// send currently installed plugins
const installed =
@ -53,6 +58,7 @@ exports.socketio = (hookName:string, args:ArgsExpressType, cb:Function) => {
socket.emit('results:installed', {installed});
});
socket.on('checkUpdates', async () => {
// Check plugins for updates
try {

View file

@ -20,7 +20,7 @@ exports.socketio = (hookName: string, {io}: any) => {
}
exports.expressPreSession = async (hookName:string, {app}:ArgsExpressType) => {
exports.expressPreSession = async (hookName:string, {app, settings}:ArgsExpressType) => {
// This endpoint is intended to conform to:
// https://www.ietf.org/archive/id/draft-inadarei-api-health-check-06.html
app.get('/health', (req:any, res:any) => {
@ -31,9 +31,12 @@ exports.expressPreSession = async (hookName:string, {app}:ArgsExpressType) => {
});
});
app.get('/stats', (req:any, res:any) => {
res.json(require('../../stats').toJSON());
});
if (settings.enableMetrics) {
app.get('/stats', (req:any, res:any) => {
res.json(require('../../stats').toJSON());
});
}
app.get('/javascript', (req:any, res:any) => {
res.send(eejs.require('ep_etherpad-lite/templates/javascript.html', {req}));

View file

@ -1,7 +1,9 @@
import {Express} from "express";
import {MapArrayType} from "./MapType";
export type ArgsExpressType = {
app:Express,
io: any,
server:any
settings: MapArrayType<any>
}

View file

@ -205,6 +205,12 @@ exports.padOptions = {
lang: null,
};
/**
* Wether to enable the /stats endpoint. The functionality in the admin menu is untouched for this.
*/
exports.enableMetrics = true
/**
* Whether certain shortcut keys are enabled for a user in the pad
*/