Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

psutil.network_io_counters returns incorrect results #248

Closed
giampaolo opened this issue May 23, 2014 · 9 comments
Closed

psutil.network_io_counters returns incorrect results #248

giampaolo opened this issue May 23, 2014 · 9 comments

Comments

@giampaolo
Copy link
Owner

From [email protected] on January 30, 2012 12:38:23

What steps will reproduce the problem?  
1. import psutil
2. psutil.network_io_counters(True) 3. 

What is the expected output?  
{'lo': iostat(bytes_sent=485737, bytes_recv=73461834, packets_sent=0, 
packets_recv=0), 'eth0': iostat(bytes_sent=802707, bytes_recv=357763247, 
packets_sent=0, packets_recv=0)} 

What do you see instead?  
{'lo:6221278': iostat(bytes_sent=447754, bytes_recv=447754, packets_sent=0, 
packets_recv=0), 'eth0:52841330': iostat(bytes_sent=960063, bytes_recv=970736, 
packets_sent=28, packets_recv=0)} 

What version of psutil are you using? What Python version?  
0.4.1 

On what operating system? Is it 32bit or 64bit version?  
Linux, both 32bit and 64bit affected. 

Please provide any additional information below.  
The bug is caused by the fact that the device name and recieved bytes are not 
separated by a space instead by ":" so split does not split them.

[root@ms ~]# cat /proc/net/dev
Inter-|   Receive                                                |  Transmit
 face |bytes    packets errs drop fifo frame compressed multicast|bytes    
packets errs drop fifo colls carrier compressed
    lo:78509297  522704    0    0    0     0          0         0 78509297  
522704    0    0    0     0       0          0
  eth0:383271109  600856    0    0    0     0          0         0 954496903  
876015    0    0    0     0       0          0

I have attached a patch that fixes the bug

Attachment: fix-network_io_counters.patch

Original issue: http://code.google.com/p/psutil/issues/detail?id=248

@giampaolo
Copy link
Owner Author

From g.rodola on January 30, 2012 04:14:16

Thanks, fixed in r1255 .

Status: Fixed
Labels: OpSys-Linux Milestone-0.5.0

@giampaolo
Copy link
Owner Author

From g.rodola on January 30, 2012 04:18:34

Status: FixedInSVN

@giampaolo
Copy link
Owner Author

From [email protected] on January 30, 2012 06:05:37

Thanks for your prompt attention to the issue. And thanks for your work on 
psutil it is a life saver.

@giampaolo
Copy link
Owner Author

From [email protected] on May 03, 2012 21:43:30

I am attaching a change to the logic in the path. I noticed a case where there 
is both space (as well as not space) between the name and the stats on the line.

Logic should be:
1) split the line by ":" to get the device and the remaining values.
2) strip() any spaces on the device
3) split() the remaining items on the line to get sent and received values.

# cat /proc/net/dev
Inter-|   Receive                                                |  Transmit
 face |bytes    packets errs drop fifo frame compressed multicast|bytes    
packets errs drop fifo colls carrier compressed
    lo:  523965    1544    0    0    0     0          0         0   523965    
1544    0    0    0     0       0          0
  eth0:699498750  762615    0 1650    0     0          0         0 69956705  
301025    0    0    0     0       0          0

###################

    for line in lines[2:]:
        name, remainder = line.split(':')
        name = name.strip()
        fields = remainder.split()
        bytes_recv = int(fields[0])
        packets_recv = int(fields[1])
        bytes_sent = int(fields[8])
        packets_sent = int(fields[9])

@giampaolo
Copy link
Owner Author

From g.rodola on May 04, 2012 03:03:09

AFAICT the current logic covers both cases, this one:

"eth0:699498750  762615    0 1..."

...and this one:

"eth0: 699498750  762615    0 1..."

Are you proposing this change because you noticed that the first number 
(699498750) gets truncated or something?

@giampaolo
Copy link
Owner Author

From [email protected] on May 04, 2012 16:39:17

I pulled _pslinux.py from the trunk. It resolved the issue I was seeing. I was 
seeing my issue from the patch attached to issue. Sorry for the confusion.

@giampaolo
Copy link
Owner Author

From g.rodola on May 09, 2012 10:29:45

Issue 263 has been merged into this issue.

@giampaolo
Copy link
Owner Author

From g.rodola on June 27, 2012 11:54:03

0.5.0 is finally out. Closing out as fixed.

Status: Fixed

@giampaolo
Copy link
Owner Author

From g.rodola on March 02, 2013 04:06:49

Updated csets after the SVN -> Mercurial migration: r1255 == revision 
cd7a6abcdb20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant