tags:

views:

322

answers:

2

Hello.

I need to count the amount (in B/kB/MB/whatever) of data sent and received by my PC, by every running program/process.

Let's say I click "Start counting" and I get the sum of everything sent/received by my browser, FTP client, system actualizations etc. etc. from that moment til I shoose "Stop".

To make it simplier, I want to count data transfered via TCP only - if it matters.

For now, I got the combo list of NICs in the PC (based on the comment in the link below). I tried to change the code given here but I failed, getting strange out-of-nowhere values in dataSent/dataReceived.

I also read the answer at the question 442409 but as I can see it is about the data sent/received by the same program, which doesn't fit my requirements.

+2  A: 

Perfmon should have counters for this type of thing that you want to do, so look there first.

Chris O
I'm sorry, I googled lots of examples, but I didn't manage to make the UL/DL counter with perfmon. If you had a bit of example code, I'd be grateful...
WRonX
These counters are per network adapter:Network Interface | Bytes Received/secNetwork Interface | Bytes Sent/secBut these only give you the current rate for a given point in time, so you must do the summation yourself over time.For your out-of-nowhere values, see if the Perfmon GUI shows the same values, maybe you can ignore that particular interface.
Chris O
A: 

Alright, I think I've found the solution, but maybe someone will suggest something better...

I made the timer (tested it with 10ms interval), which gets the "Bytes Received/sec" PerformanceCounter value and adds it to a global "temporary" variable and also increments the sum counter (if there is any lag). Then I made second timer with 1s interval, which gets the sum of values (from temporary sum), divides it by the counter and adds to the overall amount (also global). Then it resets the temporary sum and the counter.

I'm just not sure if it is right method, because I don't know, how the variables of "Bytes Received/sec" PerformanceCounter are varying during the one second. Maybe I should make some kind of histograph and get the average value?

For now, downloading 8.6MB file gave me 9.2MB overall amount - is it possible the other processes would generate that amount of net activity in less than 20 seconds?

WRonX
If you download a file of 8.6 MB you know the size of the data itself (OSI layer 7), but there is additional header data needed to get your file over the line (OSI layer 1-6). So the overall amount comes possibly from these lower levels.
Oliver
Well... there's something I don't understand. The graph is here: http://img251.imageshack.us/i/graphu.png/ (I did not count 0-values). The green line is 0Bps, blue lines are second-markers. As you can see, there is one value that is most common (it is about 2800Bps, as I can see). When the net traffic seems to lower, it always oscillates aobut that value. Why?Maybe I should count 0-values as equally important, so I'd count te average value like (100, 0, 0, 0, 200, 0)/6 ?
WRonX