How the ASP.NET application can tracking websocket traffic?

136 Views Asked by At

For a web application I'm working on, I need to measure the internet traffic that is used by web sockets (both incoming and outgoing traffic). I am using .NET 6 and ASP.NET Core SignalR, the service is deployed via K8S. I don’t need a lot of detail about the traffic used for a specific connection; I need general information for a day. I'm going to collect statistics on traffic consumption through Prometheus.

I have no experience in solving similar problems, so I have no idea which way to look. The search for ready-made solutions did not yield results.

2

There are 2 best solutions below

0
On BEST ANSWER

After testing, each http request will trigger the middleware mentioned by geldek, but websocket requests will not trigger the middleware.

We should use Hub Filter to implement it. For more details, you can check the sample code I test before, It will help you.

0
On

Write your own middleware. When the request arrives, you can inspect it and calculate the size (whatever that means for your purposes).