简体   繁体   中英

How do I get the number of clients connected to my azure webPubSub?

I'm trying to build a small app with azure webpubsub. I based it on this tutorial and I'm using javascript.

I started out by creating a function with a binding to my WebPubSub like so:

{
  "disabled": false,
  "bindings": [
    {
      "name": "wpsReq",
      "type": "webPubSubContext",
      "direction": "in"
    },
    { 
      other bindings...
    }
 ]
}

But how do i request the number of clients connected to the instance now? I tried this:

let clients = wpsReq.request.connectionContext.clientConnections.length;

but to no success.

Another way would be through the websocket, but do I have a websocket server when I work with azure webpubsub, and how would i access that?

Thanks in advance for your help.

AFAIK there is no way to get the number of connections to your Azure WebPubSub Service directly.

But there are metrics that are published to Azure Monitor, which is what you see in the Azure Portal graphs. You could expose an API that gets this value via the same request that the Azure Portal makes, which is something like this

https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.SignalRService/WebPubSub/{serviceName}/providers/microsoft.Insights/metrics?timespan=2023-01-17T11:30:00.000Z/2023-01-17T17:30:00.000Z&interval=FULL&metricnames=TotalConnectionCount&aggregation=maximum&validatedimensions=false&api-version=2019-07-01

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM