how to get file download connections on linux

KoSMoS asked:

I have a site with video content (mp4 files).

When people are watching videos, they are downloading video files from my site. I want to know the number of the active connections via the linux terminal. They are probably TCP packets on port 80.


$ netstat -an |grep :80 | wc -l

gives a huge number, ~6-7k. I don’t think that this is correct?

My answer:

netstat on Linux is obsolete and was replaced by ss which you should use instead.

Something like this ought to give you what you want:

$ ss -H state established '( sport = :https )' | wc -l

This selects connections on port 443 which are currently established, i.e. connected to a remote host, excluding those which are in the process of closing.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.