about summary refs log tree commit diff
path: root/streaming
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2023-02-03 21:29:23 +0100
committerGitHub <noreply@github.com>2023-02-03 21:29:23 +0100
commit01584f03e8159cbb7b411f33bd4f66f7131ce993 (patch)
treeb30bbd07e89beb2bf655338864b7a11ceaad2b2b /streaming
parent79ca19e9b2e701d98c80afd939a98c2a3ef74830 (diff)
Add metrics endpoint to streaming API (#23388)
Diffstat (limited to 'streaming')
-rw-r--r--streaming/index.js12
1 files changed, 12 insertions, 0 deletions
diff --git a/streaming/index.js b/streaming/index.js
index 0350c488d..e207411f2 100644
--- a/streaming/index.js
+++ b/streaming/index.js
@@ -850,6 +850,18 @@ const startWorker = async (workerId) => {
     res.end('OK');
   });
 
+  app.get('/metrics', (req, res) => server.getConnections((err, count) => {
+    res.writeHeader(200, { 'Content-Type': 'application/openmetrics-text; version=1.0.0; charset=utf-8' });
+    res.write('# TYPE connected_clients gauge\n');
+    res.write('# HELP connected_clients The number of clients connected to the streaming server\n');
+    res.write(`connected_clients ${count}.0\n`);
+    res.write('# TYPE connected_channels gauge\n');
+    res.write('# HELP connected_channels The number of Redis channels the streaming server is subscribed to\n');
+    res.write(`connected_channels ${Object.keys(subs).length}.0\n`);
+    res.write('# EOF\n');
+    res.end();
+  }));
+
   app.use(authenticationMiddleware);
   app.use(errorMiddleware);