Measuring bytes of packet sent from python application

Steven D'Aprano steven at REMOVE.THIS.cybersource.com.au
Mon Jan 5 20:53:17 EST 2009


On Mon, 05 Jan 2009 18:23:10 -0500, Kangkook Jee wrote:

> Jonathan Gardner wrote:
>> On Jan 5, 2:26 pm, Kangkook Jee <aixe... at gmail.com> wrote:
>>> I'd like to measure number of bytes sent(or recv'd) from my python
>>> application. Does anyone have any idea how can I achieve this?
>>>
>>> I tried to do this by tracing some socket calls (send, sendto,
>>> sendAll)
>>>   using 'metaclass' but I could find exactly place that I can put this
>>>   in.
>>>
>>> My application runs some number of protocols (bittorrent, xmlrpc ..)
>>> in it and will be measured for a couple of hours.
>>>
>>>
>> A good universal tool on the Linux platform is tcpdump. It takes some
>> learning, but is very useful for this kind of task. You can use a tool
>> like ethereal to visualize the data that tcpdump gathers.
> 
> Thanks a lot Jonathan
> 
> That seems like a good solution for my issue but how can I distinguish
> traffics from my application to others?
> 
> I'm still struggling to solve it within python process since it looks
> cleaner but it doesn't seems to be easy at all.


A relatively straightforward, if not totally accurate, way of doing that 
is to create a layer between your application code and the network 
libraries, and have the layer measure the amount of data you send before 
it reaches the specific protocols being used. 

Naturally this won't give you a totally accurate count of network traffic 
sent from your application, since every protocol includes some overhead, 
but that might not matter for your use-case.



-- 
Steven



More information about the Python-list mailing list