How to Get the Current Network Interface Throughput Statistics on Linux/Unix

How can I get the current network interface throughput statistics on Linux/UNIX?

You can parse the output of ifconfig

Get the current bandwidth use in Linux with PHP

If the guests are also running Linux or they have separate interfaces on the host, you can cat /sys/class/net/$interface_name/statistics/rx_bytes and tx_bytes, just compare the difference and divide by time to get an estimate of current throughput.

How to reliably measure the network bandwidth used by a process

Can the application be isolated on a single machine?

Does anything else have to run on the system?

If a system can be dedicated this way, periodically grab the last line from /proc/net/netstat and subtract the corresponding values of InOctets and OutOctets.

This system, Fedora 15, shows this after 23 days of uptime:

TcpExt: SyncookiesSent SyncookiesRecv SyncookiesFailed EmbryonicRsts PruneCalled RcvPruned OfoPruned OutOfWindowIcmps LockDroppedIcmps ArpFilter TW TWRecycled TWKilled PAWSPassive PAWSActive PAWSEstab DelayedACKs DelayedACKLocked DelayedACKLost ListenOverflows ListenDrops TCPPrequeued TCPDirectCopyFromBacklog TCPDirectCopyFromPrequeue TCPPrequeueDropped TCPHPHits TCPHPHitsToUser TCPPureAcks TCPHPAcks TCPRenoRecovery TCPSackRecovery TCPSACKReneging TCPFACKReorder TCPSACKReorder TCPRenoReorder TCPTSReorder TCPFullUndo TCPPartialUndo TCPDSACKUndo TCPLossUndo TCPLoss TCPLostRetransmit TCPRenoFailures TCPSackFailures TCPLossFailures TCPFastRetrans TCPForwardRetrans TCPSlowStartRetrans TCPTimeouts TCPRenoRecoveryFail TCPSackRecoveryFail TCPSchedulerFailed TCPRcvCollapsed TCPDSACKOldSent TCPDSACKOfoSent TCPDSACKRecv TCPDSACKOfoRecv TCPAbortOnSyn TCPAbortOnData TCPAbortOnClose TCPAbortOnMemory TCPAbortOnTimeout TCPAbortOnLinger TCPAbortFailed TCPMemoryPressures TCPSACKDiscard TCPDSACKIgnoredOld TCPDSACKIgnoredNoUndo TCPSpuriousRTOs TCPMD6NotFound TCPMD5Unexpected TCPSackShifted TCPSackMerged TCPSackShiftFallback TCPBacklogDrop TCPMinTTLDrop TCPDeferAcceptDrop IPReversePathFilter TCPTimeWaitOverflow TCPReqQFullDoCookies TCPReqQFullDrop
TcpExt: 0 0 0 0 0 0 0 0 10 0 67116 0 0 0 0 8 117271 53 18860 0 0 102295 23352211 87967244 0 16861098 118195 893786 881659 0 29 10 0 0 0 9 10 16 12 2321 21 0 1 156 39 940 13 921 8015 0 1 2 0 18461 22 941 0 0 2974 15422 0 709 0 0 0 1 8 119 3 0 0 0 0 25231 0 0 0 4 0 0 0
IpExt: InNoRoutes InTruncatedPkts InMcastPkts OutMcastPkts InBcastPkts OutBcastPkts InOctets OutOctets InMcastOctets OutMcastOctets InBcastOctets OutBcastOctets
IpExt: 0 0 25308 48 725 1 24434248973 4218365129 2181277 13241 365505 65

Of course, that format is unfriendly for here, but fairly nice for scripting languages to deal with. You can see the depth and variety of information! The last line shows that this system has read 24,434,248,973 bytes and written 4,218,365,129. (It is on day nine of scraping a large website.)

how can I get maximum bandwidth of an interface in linux C?

iperf can help you measure actual bandwidth
http://sourceforge.net/projects/iperf/

Linux Network Interface Usage Monitoring in C/C++

One of the simplest ways is to parse the file: /proc/net/dev

Mine contains:

Inter-|   Receive                                                |  Transmit
face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
lo: 44865 1431 0 0 0 0 0 0 44865 1431 0 0 0 0 0 0
eth0:150117850 313734 0 0 0 0 0 0 34347178 271210 0 0 0 0 0 0
pan0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

You could then write a parser that uses nothing other than the C/C++ libraries.

Network usage top/htop on Linux

jnettop is another candidate.

edit: it only shows the streams, not the owner processes.

How to get process or port Network bandwidth usage in linux

As far as I know Linux doesn't offer an alternative interface to pcap for calculating network usage. /proc/<PID>/stat(us) contains various process information but nothing about network access, only the total I/O usage including disk access.

Similarly, to know the port you have to read at least the IP header. Hence I assume it is not possible to speed this up significantly, because analyzing all packets in user space will always be slow. A kernel module for this task seems to be the only option.



Related Topics



Leave a reply



Submit