Some broadband providers impose a monthly download limit, charging extra if you go over. It is also quite easy to exceed some of the lower limits just by installing/updating packages and 'normal' browsing (which to me includes streaming TV programs and movies).
This means that you need to limit the amount you use the internet, yet it is hard to know when.
The System Monitor helps a bit with this by giving a total received/total sent in the networking section of the Resources tab. However, this is reset every reboot. It would be good if there was a way to have a monthly total received so you can know how close you are to exceeding your limit and maybe even be given warnings if it looks like you are going to exceed the limits.
Does anyone know of a way to achieve this?
vnStat - Light Weight Console-based Network Monitor
vnStat is a console-based network traffic monitor for Linux and BSD that keeps a log of network traffic for the selected interface(s). It uses the network interface statistics provided by the kernel as information source. This means that vnStat won't actually be sniffing any traffic and also ensures light use of system resources.
In this tutorial we'll review:
Features
Installation
nvStat is in the official repositories so no need to link to a new ppa. To install create a Terminal instance using Ctrl+Alt+T and type at the prompt:
After installation, keep your Terminal open for the following sections. There is no need to reboot.
Configuration
Pick a preferred network interface and edit the Interface variable in the
/etc/vnstat.conf
accordingly. To the list all interfaces available to vnstat, use:To start monitoring a particular interface you must initialize a database first. Each interface needs its own database. The command to initialize one for the eth0 interface is:
Start Systemd Service
After introducing the interface(s) and checking the config file. You can start the monitoring process via
systemd
:To make this service permanent use:
From now on
vnstat
will be gathering network usage in the background using such a small percentage of CPU it doesn't show up on conky's (system monitor's) top 9 list of processes (on my machine).Usage (from Command Line)
Query the network traffic:
Viewing live network traffic usage:
To find more options, use:
Monthly Totals
To see monthly totals, use:
Conky example
Conky is a popular light-weight System Monitor used across many Linux distributions. You can vnStat bandwidth totals to your conky display like this:
Note when picture was taken
Yesterday
was Sunday which explains why the Weekly total is less.The conky code to achieve this is:
To save space on my narrow window I used "G" instead of "GiB", "M" instead of "MiB", etc. If you have more screen realestate change
substr ($10, 1, 1)
to$10
and the same for$9
.You may have to change
eth0
towlan0
oreth1
, etc. depending on your network name reported byifconfig
.You can check out vnstat. It is command-line based and is available in the repository.
You can start it with
sudo vnstat -u -i [interface]
To see the stats
sudo vnstat -i [interface]
Just to expand rickys anwer:
With
ifconfig | cut -c 1-8 | sort | uniq -u
you can list the interfaces:For one interface, you can then visualize the traffic like this:
gives a nice summary:
rx
is the received traffictx
is the transferred trafficThough not a "ubuntu" answer, I use the Tomato firmware on my WRT54G router for this. It gives me monthly up/down usage for the past couple of years, and the nice thing (in the context of your question) is that it is for the whole network, not just the one system it's running on (though this point is moot if the system in question is your router or directly connected).
I recommend the ntop utility which is available from the repositories, it runs as a service ands keeps traffic usage records. The reports are available from am internal http server (port 3000). You can easily check them using a browser,
http://localhost:300/
Check what you can get from ntop at the ntop website .
Apart from any software solution I would suggest looking at your provider. Many of them have monitoring tools which send you a warning when you reach a certain limit or block your access temporarily. This has the advantage that you get some "official" number.
I found "download monitor" as very good and easy to use tool to show data stats. It has GUI interface which makes it very easy to use. It is available on Ubuntu Software Center.