I do not need some kind of realtime visual status of my ethernet - I want to run my script when last five minutes I uploaded less than X. So I need to get only one number from some command. What can you recommend?
I use Ubuntu 14.04.
ifconfig <interface> gives you throughput of a specific interface.
root@trinity:~# ifconfig eth0 eth0 Link encap:Ethernet HWaddr 28:92:4a:32:0c:43 inet addr:192.168.1.10 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::2a92:4aff:fe32:c43/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1554100056 errors:0 dropped:3528 overruns:0 frame:15941 TX packets:570492690 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:2186365577866 (1.9 TiB) TX bytes:180850207310 (168.4 GiB) Interrupt:18
Just read the TX bytes bit and do the maths. You'll need to track it in a file somewhere so you can work out the differential.
ifconfig command is being deprecated, and people will suggest using
ip. The relevant command with
root@trinity:~# ip -s link ls eth0 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT qlen 1000 link/ether 28:92:4a:32:0c:43 brd ff:ff:ff:ff:ff:ff RX: bytes packets errors dropped overrun mcast 2186366161514 1554101939 0 3197 15941 9994871 TX: bytes packets errors dropped carrier collsns 180850392034 570493984 0 0 0 0
Under Linux, reading
/sys/class/net/<interface>/rx_bytes (depending on which direction you're interested in) is a good way to get the counters for the number of bytes received and the number of bytes sent on an interface. The counters are also available together for all interfaces in
/proc/net/dev but you will have to do more parsing. You can read the values before you start transferring and read them again 5 minutes later then subtract to get the amount transferred during the 5 minute period.