Re: Wrong network usage reported by /proc

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Eric Dumazet
Date: Tuesday, May 5, 2009 - 1:51 am

Matthias Saou a écrit :

Your python script is buggy, since space after ':' is optional

# cat /proc/net/dev | cut -c1-80
Inter-|   Receive                                                |  Transmit
 face |bytes    packets errs drop fifo frame compressed multicast|bytes    packe
    lo:   16056      36    0    0    0     0          0         0    16056
  eth0:624245505 7370445    0    0    0     0          0       108 586782291 737
  eth1:2512329067 11360819    0    0    0     0          0         0 2521050992
 bond0:3378296009 15279963    0    0    0     0          0         0 3390533080
 bond1:       0       0    0    0    0     0          0         0        0
  eth2:865966942 3919144    0    0    0     0          0         0 869482088 391
  eth3:       0       0    0    0    0     0          0         0        0
vlan.103: 1277511   18134    0    0    0     0          0         0  3439082   1
vlan.825:3095633732 15533200    0    0    0     0          0         0 332349968


So your read_proc() is wrong, since is uses line.split

def read_proc(interface):
    f = open('/proc/net/dev')
    for line in f:
        values = line.split()
        i = values[0].split(':')[0]
        if interface == i:
            bytes = int(values[8])
            # received bytes
            # bytes = int(values[0].split(':')[1])
            f.close()
            return bytes
    f.close()


BTW, your tcpdump might report lower values too, since it doesnt account for all headers, nor
non IP frames, or forwarded frames (source IP is then not your host IP)



--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: Wrong network usage reported by /proc, Eric Dumazet, (Mon May 4, 10:53 am)
Re: Wrong network usage reported by /proc, Matthias Saou, (Mon May 4, 12:11 pm)
Re: Wrong network usage reported by /proc, Willy Tarreau, (Mon May 4, 10:04 pm)
Re: Wrong network usage reported by /proc, Eric Dumazet, (Mon May 4, 10:22 pm)
Re: Wrong network usage reported by /proc, Willy Tarreau, (Mon May 4, 10:50 pm)
Re: Wrong network usage reported by /proc, Matthias Saou, (Tue May 5, 1:09 am)
Re: Wrong network usage reported by /proc, Eric Dumazet, (Tue May 5, 1:51 am)
Re: Wrong network usage reported by /proc, Matthias Saou, (Thu May 7, 10:58 am)