Add streaming stats endpoint
This commit is contained in:
parent
b5603d9ee6
commit
b2e0d39a04
|
@ -159,6 +159,8 @@ const startWorker = (workerId) => {
|
||||||
*/
|
*/
|
||||||
const subs = {};
|
const subs = {};
|
||||||
|
|
||||||
|
let stats = {};
|
||||||
|
|
||||||
redisSubscribeClient.on('message', (channel, message) => {
|
redisSubscribeClient.on('message', (channel, message) => {
|
||||||
const callbacks = subs[channel];
|
const callbacks = subs[channel];
|
||||||
|
|
||||||
|
@ -752,6 +754,11 @@ const startWorker = (workerId) => {
|
||||||
res.end('OK');
|
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(authenticationMiddleware);
|
||||||
app.use(errorMiddleware);
|
app.use(errorMiddleware);
|
||||||
|
|
||||||
|
@ -1362,15 +1369,20 @@ const startWorker = (workerId) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
|
let count = 0;
|
||||||
|
|
||||||
wss.clients.forEach(ws => {
|
wss.clients.forEach(ws => {
|
||||||
if (ws.isAlive === false) {
|
if (ws.isAlive === false) {
|
||||||
ws.terminate();
|
ws.terminate();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
count++;
|
||||||
ws.isAlive = false;
|
ws.isAlive = false;
|
||||||
ws.ping('', false);
|
ws.ping('', false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
stats = { ...stats, connectionCounts: count };
|
||||||
}, 30000);
|
}, 30000);
|
||||||
|
|
||||||
attachServerWithConfig(server, address => {
|
attachServerWithConfig(server, address => {
|
||||||
|
|
Loading…
Reference in a new issue