Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to measure how many TCP connections were made in a page

With chrome dev tool, I can see the number of requests in a page, but it seems that there is no way to measure number of connections.

Is it possible in chrome dev tool? if not, what tools can I use instead?

like image 589
Weihang Jian Avatar asked Jan 10 '17 15:01

Weihang Jian


People also ask

How do I know how many TCP connections?

Use netstat , ss or files inside proc filesystem to count TCP connections.

How many TCP connections are there at once?

On the TCP level the tuple (source ip, source port, destination ip, destination port) must be unique for each simultaneous connection. That means a single client cannot open more than 65535 simultaneous connections to a single server. But a server can (theoretically) serve 65535 simultaneous connections per client.

How do I know the number of TCP connections in Wireshark?

If you prefer a GUI based tool, Wireshark can analyze TCP connections. It assigns a number to each TCP connection it finds in the file, so you can just scroll to the bottom of the file and look what number the last connection got assigned.

How many TCP sessions are contained in the dump file?

3. How many TCP Sessions are contained in the dump file? Again, no real challenge here… All you have to do is group by the tcp_session field and you can easily see that there are 5 sessions.


2 Answers

You can enable the Connection ID header in the Network panel, which is a unique identifier for a particular connection. You can sort the column to see how many requests there were for a particular connection instance, but there's no built in way to see how many or filter the results.

Network Panel Connection ID

However, this data can be exported into a JSON formatted file, known as the HAR (HTTP Archive). You can do this by right-clicking on panel and selecting 'Save as HAR with Content'.

You can extract the data from the JSON, and filter and aggregate however you like. I have created a simple example script that will load the HAR from the local file system, parse the data, and filter the content, so that it shows how many unique Connection IDs appeared in the session.

function loadFile(event) {
    var file = event.target.files[0];

    if (file) {
        var reader = new FileReader();
        reader.onload = function(e) {
            var contents = e.target.result;
            var data = JSON.parse(contents);
            getUniqueConnectionCount(data);
        }
        reader.readAsText(file);
    } else {
        alert('Failed to load file.');
    }
}

function getUniqueConnectionCount(data) {
    var entries = data.log.entries;
    var uniqueConnectionIds = entries.map(function(item) {
        return item['connection'];
    }).filter(function(x, i, a) {
        return a.indexOf(x) === i && i > 0;
    });

    console.log('There were ', uniqueConnectionIds.length, ' unique connections found', uniqueConnectionIds);
}

document.getElementById('files').addEventListener('change', loadFile, false);
<div>
  <input type='file' id='files' name='files' />
</div>

Note: Make sure 'Preserve Log' is un-checked to avoid seeing data from previous sessions. This is just a quick example for your use case, but I might look into extending this to be more generic.

like image 96
Gideon Pyzer Avatar answered Nov 10 '22 09:11

Gideon Pyzer


It depends what connections you are interested in. You can use Chrome Developer tools the way Gideon Pyzer pointed out to see html connections. But if you are interested in TCP or some other protocol you can use Wireshark (free and open-source packet analyzer) to capture those connections.

Then there is "Capture Network Log" in chrome. Type "chrome://net-export/" in address field, set ready and press "Start Loggin to Disk" button - it will save your browser network activity to json file.

like image 33
Rustam A. Avatar answered Nov 10 '22 09:11

Rustam A.