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.
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.