Ubuntu – How to view internet/network usage for a single session

internetnetworking

I would like to view the internet usage for a single session, for example I connect to the WiFi at my local library which has a 200MB limit.
Is it possible to connect and start tracking the data use – starting from zero and simply keep tracking until I reset or clear the history?

I have looked into

  • Ubuntu's pre-installed system monitor – this seems to track the total historical data for some given period
  • vnstat – same problem – by default -it aggregates historical data – e.g. how much data has already been used in sessions that have been and gone.

Best Answer

You can try a workaround using vnstat

man vnstat

-l, --live mode
              Display current transfer rate for the selected interface in real
              time until interrupted. Statistics will be shown after interrup‐
              tion if the runtime was more than 10 seconds. An  optional  mode
              parameter  can be used to select between the displaying of pack‐
              ets per second (mode 0) and transfer counters  (mode  1)  during
              execution.  --style can also be used to affect the layout of the
              output.

So you can use the live mode, this require manual starting and closing so start monitoring when start your session by running the command vnstat -l and close it by (ctrl+c) when you end your session.

$ vnstat -l

Monitoring eth0...    (press CTRL-C to stop)

   rx:        0 kbit/s     1 p/s          tx:        0 kbit/s     0 p/s^C


 eth0  /  traffic statistics

                           rx         |       tx
--------------------------------------+------------------
  bytes                      246 KiB  |         232 KiB
--------------------------------------+------------------
          max             624 kbit/s  |      620 kbit/s
      average           59.64 kbit/s  |    56.24 kbit/s
          min               0 kbit/s  |        0 kbit/s
--------------------------------------+------------------
  packets                        745  |             595
--------------------------------------+------------------
          max                121 p/s  |          86 p/s
      average                 22 p/s  |          18 p/s
          min                  1 p/s  |           0 p/s
--------------------------------------+------------------
  time                    33 seconds

If you want to see the result in live mode use the mode 1

$ vnstat -l 1

Monitoring eth0...    (press CTRL-C to stop)

   rx:      4 kbit/s   48 KiB             tx:     28 kbit/s   270 KiB

AS seen above received from starting the command is 48K running 4K/s while the transmitting is 270K running 28K/s

I think this is what do you want exactly

Another possible solution

Bitmeter OS

BitMeter OS is a free, open-source, bandwidth monitor that works on Windows, Linux and Mac OSX. BitMeter OS keeps track of how much you use your internet/network connection, and allows you to view this information either via a web browser, or by using the command line tools.

Download your version from here.

Now you can easily install it using

sudo dpkg -i bitmeter*.deb

Once it's installed locate your browser to http://localhost:2605/

enter image description here

Now to do the trick for your needs Go to Alert tab.

enter image description here

create a new Alert specifying the amount of data for Internet and time for your sessions. take a look for.

Related Question