express: New `httpUptime` metric

pull/4776/head
Richard Hansen 2021-02-13 01:40:54 -05:00 committed by John McLear
parent e22d8dffc0
commit ac52fb8a9d
2 changed files with 6 additions and 1 deletions

View File

@ -26,7 +26,8 @@
* Database performance is significantly improved. * Database performance is significantly improved.
* Admin UI now has test coverage in CI. (The tests are not enabled by default; * Admin UI now has test coverage in CI. (The tests are not enabled by default;
see `settings.json`.) see `settings.json`.)
* New stats: `activePads`, `lastDisconnected`, `memoryUsageHeap`. * New stats/metrics: `activePads`, `httpUptime`, `lastDisconnected`,
`memoryUsageHeap`.
* For plugin authors: * For plugin authors:
* New `callAllSerial()` function that invokes hook functions like `callAll()` * New `callAllSerial()` function that invokes hook functions like `callAll()`
except it supports asynchronous hook functions. except it supports asynchronous hook functions.

View File

@ -17,6 +17,7 @@ const logger = log4js.getLogger('http');
let serverName; let serverName;
const sockets = new Set(); const sockets = new Set();
const socketsEvents = new events.EventEmitter(); const socketsEvents = new events.EventEmitter();
let startTime = null;
exports.server = null; exports.server = null;
@ -49,6 +50,7 @@ const closeServer = async () => {
}; };
exports.createServer = async () => { exports.createServer = async () => {
stats.gauge('httpUptime', () => startTime == null ? 0 : new Date() - startTime);
console.log('Report bugs at https://github.com/ether/etherpad-lite/issues'); console.log('Report bugs at https://github.com/ether/etherpad-lite/issues');
serverName = `Etherpad ${settings.getGitCommit()} (https://etherpad.org)`; serverName = `Etherpad ${settings.getGitCommit()} (https://etherpad.org)`;
@ -215,6 +217,8 @@ exports.restartServer = async () => {
}); });
}); });
await util.promisify(exports.server.listen).bind(exports.server)(settings.port, settings.ip); await util.promisify(exports.server.listen).bind(exports.server)(settings.port, settings.ip);
startTime = new Date();
logger.info('HTTP server listening for connections');
}; };
exports.shutdown = async (hookName, context) => { exports.shutdown = async (hookName, context) => {