How to track internet usage (upload & download) on Linux?

26

12

I use a broadband modem to connect to internet on my linux machine. I've used the gnome-system-monitor app that correctly displays the kbps as well as total bytes consumed in each session. Now, is there any easy way in linux for me to log all these consumptions (downloads and uploads)?

The thing is that I use a limited usage plan (n number of GBs each month), hence I want to keep track of my usage. What is the best approach to do this on linux?

Prahlad Yeri

Posted 2013-07-05T15:37:39.397

Reputation: 841

Very similar, bordering on duplicate: Is there any way to see how much data I sent via Internet? at Unix.SE

– a CVn – 2013-07-05T15:54:39.367

Answers

33

Install vnstat, it gives logs the usage on a network interface and you can display the usage over different time periods.

Here's the default output from my system

                  rx      /      tx      /     total    /   estimated
eth0:
   Jun '13     14.40 GiB  /    1.70 GiB  /   16.10 GiB
   Jul '13      3.57 GiB  /    2.55 GiB  /    6.12 GiB  /   40.44 GiB
 yesterday    968.58 MiB  /    2.26 GiB  /    3.21 GiB
     today    377.88 MiB  /   26.73 MiB  /  404.61 MiB  /     582 MiB

If you get vnstati as well, you can display the data in different ways e.g.

Usage graph

parkydr

Posted 2013-07-05T15:37:39.397

Reputation: 2 074

Which command did you use to get this nice image? When I use vnstati -d it only says At least output mode and file parameter needs to be given. – Martin Thoma – 2016-05-12T11:27:19.177

4The image shows a vertical summary (-vs option) and you need an output file (-o option), so the command to output the above image to foo.png is 'vnstati -vs -o foo.png' – parkydr – 2016-05-12T20:37:42.263

Thank you. And what is rx and TX? – Martin Thoma – 2016-05-12T21:53:38.383

4Rx - receive Tx transmit – parkydr – 2016-05-13T12:46:17.813

Thank you very much. What do you think about adding this to your answer? So how you find what your wlan interface is and vnstati -vs -i wlp3s0 -o ~/summary.png – Martin Thoma – 2016-05-13T15:51:29.573

2ifconfig will show you your networks – parkydr – 2016-05-15T19:55:11.570

3

Easiest to use and easiest to control output and redirect to file for continuous logging:

ifstat

Probably comes with most linux distributions, and can be installed with brew on mac. Highly recommended.

samthebest

Posted 2013-07-05T15:37:39.397

Reputation: 203

3

vnstat is probably the best way to do this. It can be installed using the following command in terminal:

sudo apt-get install vnstat

If you don't want to keep checking the data usage status every time then use:

watch -n 5 --differences vnstat -d eth0

It would display the status every 5 seconds in the open terminal with the differences that occur in the values. -d is used to display the status of each day and eth0 is the ethernet used for internet connection (wlan0 may be used for WiFi).

CapeAndCowl

Posted 2013-07-05T15:37:39.397

Reputation: 31