Add streaming stats endpoint
This commit is contained in:
parent
b5603d9ee6
commit
b2e0d39a04
|
@ -159,6 +159,8 @@ const startWorker = (workerId) => {
|
|||
*/
|
||||
const subs = {};
|
||||
|
||||
let stats = {};
|
||||
|
||||
redisSubscribeClient.on('message', (channel, message) => {
|
||||
const callbacks = subs[channel];
|
||||
|
||||
|
@ -752,6 +754,11 @@ const startWorker = (workerId) => {
|
|||
res.end('OK');
|
||||
});
|
||||
|
||||
app.get('/api/v1/streaming/stats', (req, res) => {
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify(stats));
|
||||
});
|
||||
|
||||
app.use(authenticationMiddleware);
|
||||
app.use(errorMiddleware);
|
||||
|
||||
|
@ -1362,15 +1369,20 @@ const startWorker = (workerId) => {
|
|||
});
|
||||
|
||||
setInterval(() => {
|
||||
let count = 0;
|
||||
|
||||
wss.clients.forEach(ws => {
|
||||
if (ws.isAlive === false) {
|
||||
ws.terminate();
|
||||
return;
|
||||
}
|
||||
|
||||
count++;
|
||||
ws.isAlive = false;
|
||||
ws.ping('', false);
|
||||
});
|
||||
|
||||
stats = { ...stats, connectionCounts: count };
|
||||
}, 30000);
|
||||
|
||||
attachServerWithConfig(server, address => {
|
||||
|
|
Loading…
Reference in New Issue