Skip to content

Commit

Permalink
Add streaming stats endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
noellabo authored and atsu1125 committed Mar 10, 2023
1 parent 60ac893 commit 4572f95
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions streaming/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ const startWorker = async (workerId) => {
*/
const subs = {};

let stats = {};

const redisSubscribeClient = await redisUrlToClient(redisParams, process.env.REDIS_URL);
const redisClient = await redisUrlToClient(redisParams, process.env.REDIS_URL);

Expand Down Expand Up @@ -785,6 +787,11 @@ const startWorker = async (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);

Expand Down Expand Up @@ -1174,15 +1181,20 @@ const startWorker = async (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 => {
Expand Down

0 comments on commit 4572f95

Please sign in to comment.