So running internet with a dialup connection in India is pain on the butt.That is why one needs to measure the bandwidth he/she is getting from their service provider.
I do not issue any guarantee that this will work for you.
I am gonna use age old tool called "Vnstat"; you can find it here.
Now once you got the software( As I have four different version of GNU/Linux running in my laptop..so it's installation procedure would be different) But for the sake of clarity I am sticking with Gentoo.
Step 1: Install the software
bhaskar@bhaskar-laptop_09:39:03_Tue Jul 20:~> sudo emerge -av vnstat
Password:
These are the packages that would be merged, in order:
Calculating dependencies... done!
[ebuild R ] net-analyzer/vnstat-1.10 USE="-gd" 0 kB
Total: 1 package (1 reinstall), Size of downloads: 0 kB
Would you like to merge these packages? [Yes/No]
Here I put N, because I have installed it long time back and using it for quite some time.If you put Y then it will fetch the software from the site and install it.I decided not to reinstall it.The " R" signifies "Reinstall".
Step 2: Get the file install in the system
bhaskar@bhaskar-laptop_09:50:07_Tue Jul 20:~> sudo qlist vnstat
/var/run/vnstatd/.keep_net-analyzer_vnstat-0
/var/lib/vnstat/.keep_net-analyzer_vnstat-0
/usr/share/doc/vnstat-1.10/FAQ.bz2
/usr/share/doc/vnstat-1.10/README.setup.bz2
/usr/share/doc/vnstat-1.10/README.bz2
/usr/share/doc/vnstat-1.10/CHANGES.bz2
/usr/share/doc/vnstat-1.10/vnstat.cgi.bz2
/usr/share/doc/vnstat-1.10/ip-up.example.bz2
/usr/share/doc/vnstat-1.10/ip-down.example.bz2
/usr/share/doc/vnstat-1.10/UPGRADE.bz2
/usr/share/man/man1/vnstat.1.bz2
/usr/share/man/man1/vnstatd.1.bz2
/usr/bin/vnstatd
/usr/bin/vnstat
/etc/init.d/vnstatd
/etc/vnstat.conf
/etc/conf.d/vnstatd
/etc/cron.hourly/vnstat
Step 3: Main files to interact with
/var/lib/vnstat/
This directory contains all databases the program uses. Files are named according to the monitored interfaces.
/etc/vnstat.conf
Config file that will be used unless $HOME/.vnstatrc exists. See vnstat.conf(5) for more information.
Step 4: Get the particular interface initialised with it and create database for it
bhaskar@bhaskar-laptop_09:53:30_Tue Jul 20:~> sudo /usr/bin/vnstat -u -i ppp0
So it does basically create a database file for the interface of ppp0 and make a mark for update of it.The option "u" for update and "i" to initialize that interface. It could be eth0, wlan0 etc.
Step 5:Get the statistics on your terminal
bhaskar@bhaskar-laptop_09:56:22_Tue Jul 20:~> sudo vnstat
Password:
Database updated: Tue Jul 20 09:55:32 2010
ppp0 since 11/28/09
rx: 6.47 GiB tx: 933.61 MiB total: 7.38 GiB
monthly
rx | tx | total | avg. rate
------------------------+-------------+-------------+---------------
Jun '10 1.16 GiB | 167.63 MiB | 1.32 GiB | 4.28 kbit/s
Jul '10 1.15 GiB | 276.73 MiB | 1.42 GiB | 7.09 kbit/s
------------------------+-------------+-------------+---------------
estimated 1.83 GiB | 440 MiB | 2.26 GiB |
daily
rx | tx | total | avg. rate
------------------------+-------------+-------------+---------------
yesterday 120.60 MiB | 22.15 MiB | 142.76 MiB | 13.54 kbit/s
today 4.53 MiB | 1.13 MiB | 5.66 MiB | 1.30 kbit/s
------------------------+-------------+-------------+---------------
estimated 9 MiB | 2 MiB | 11 MiB |
Now if you want some specific statistics of a month or day or year;you can do so by this:
Step 6: Specific to days
sudo vnstat -d
ppp0 / daily
day rx | tx | total | avg. rate
------------------------+-------------+-------------+---------------
05/20/10 14.31 MiB | 4.34 MiB | 18.66 MiB | 1.77 kbit/s
05/24/10 85.00 MiB | 9.21 MiB | 94.21 MiB | 8.93 kbit/s
05/25/10 11.93 MiB | 3.19 MiB | 15.12 MiB | 1.43 kbit/s
05/26/10 56.32 MiB | 11.70 MiB | 68.02 MiB | 6.45 kbit/s
05/31/10 224.23 MiB | 22.86 MiB | 247.09 MiB | 23.43 kbit/s
06/01/10 59.62 MiB | 13.77 MiB | 73.40 MiB | 6.96 kbit/s
06/04/10 61.85 MiB | 15.58 MiB | 77.43 MiB | 7.34 kbit/s
06/06/10 12.85 MiB | 2.96 MiB | 15.80 MiB | 1.50 kbit/s
06/10/10 167.88 MiB | 13.60 MiB | 181.48 MiB | 17.21 kbit/s
06/13/10 199.02 MiB | 17.05 MiB | 216.07 MiB | 20.49 kbit/s
06/14/10 18.29 MiB | 1.91 MiB | 20.20 MiB | 1.92 kbit/s
06/16/10 169.26 MiB | 18.28 MiB | 187.54 MiB | 17.78 kbit/s
06/20/10 114.46 MiB | 15.88 MiB | 130.34 MiB | 12.36 kbit/s
06/22/10 39.43 MiB | 8.71 MiB | 48.14 MiB | 4.56 kbit/s
06/27/10 28.28 MiB | 8.23 MiB | 36.51 MiB | 3.46 kbit/s
06/30/10 315.76 MiB | 51.66 MiB | 367.42 MiB | 34.84 kbit/s
07/01/10 171.94 MiB | 45.67 MiB | 217.60 MiB | 20.63 kbit/s
07/02/10 37.74 MiB | 13.36 MiB | 51.10 MiB | 4.84 kbit/s
07/05/10 57.69 MiB | 16.18 MiB | 73.87 MiB | 7.00 kbit/s
07/06/10 119.98 MiB | 24.60 MiB | 144.58 MiB | 13.71 kbit/s
07/08/10 71.45 MiB | 19.33 MiB | 90.78 MiB | 8.61 kbit/s
07/11/10 296.82 MiB | 32.26 MiB | 329.08 MiB | 31.20 kbit/s
07/12/10 121.50 MiB | 26.05 MiB | 147.54 MiB | 13.99 kbit/s
07/13/10 30.79 MiB | 19.54 MiB | 50.33 MiB | 4.77 kbit/s
07/14/10 58.40 MiB | 25.19 MiB | 83.59 MiB | 7.93 kbit/s
07/15/10 39.39 MiB | 15.02 MiB | 54.40 MiB | 5.16 kbit/s
07/17/10 32.30 MiB | 11.46 MiB | 43.76 MiB | 4.15 kbit/s
07/18/10 12.51 MiB | 4.80 MiB | 17.31 MiB | 1.64 kbit/s
07/19/10 120.60 MiB | 22.15 MiB | 142.76 MiB | 13.54 kbit/s
07/20/10 4.53 MiB | 1.13 MiB | 5.66 MiB | 1.30 kbit/s
------------------------+-------------+-------------+---------------
estimated 9 MiB | 2 MiB | 11 MiB |
Now to get the hourly stat out of this.
Step 7:Hourly stat
sudo vnstat -h
ppp0 09:55
^ r
| r r
| r r
| r r
| r r
| r r
| r r r
| r r r
| r r r r r
| rt r rt r r rt r
-+--------------------------------------------------------------------------->
| 10 11 12 13 14 15 16 17 18 19 20 21 22 23 00 01 02 03 04 05 06 07 08 09
h rx (KiB) tx (KiB) h rx (KiB) tx (KiB) h rx (KiB) tx (KiB)
10 11011 4344 18 0 0 02 0 0
11 9700 3176 19 0 0 03 0 0
12 0 0 20 0 0 04 0 0
13 16154 4001 21 0 0 05 0 0
14 39047 2395 22 0 0 06 0 0
15 37631 3193 23 0 0 07 0 0
16 7794 4202 00 0 0 08 0 0
17 2167 1377 01 0 0 09 4636 1161
Now want to get some statistics related to months,here is how to get it
Step 8:
bhaskar@bhaskar-laptop_10:01:55_Tue Jul 20:~> sudo vnstat -m
ppp0 / monthly
month rx | tx | total | avg. rate
------------------------+-------------+-------------+---------------
Nov '09 0 KiB | 0 KiB | 0 KiB | 0.00 kbit/s
Feb '10 17.67 MiB | 1.46 MiB | 19.12 MiB | 0.06 kbit/s
Mar '10 1.22 GiB | 99.70 MiB | 1.32 GiB | 4.14 kbit/s
Apr '10 1.32 GiB | 204.41 MiB | 1.52 GiB | 4.93 kbit/s
May '10 1.60 GiB | 183.68 MiB | 1.77 GiB | 5.56 kbit/s
Jun '10 1.16 GiB | 167.63 MiB | 1.32 GiB | 4.28 kbit/s
Jul '10 1.15 GiB | 276.84 MiB | 1.42 GiB | 7.09 kbit/s
------------------------+-------------+-------------+---------------
estimated 1.83 GiB | 440 MiB | 2.26 GiB |
Now lets get some stat about the week
Step 9: Weekly stat
bhaskar@bhaskar-laptop_10:06:04_Tue Jul 20:~> sudo vnstat -w
ppp0 / weekly
rx | tx | total | avg. rate
---------------------------+-------------+-------------+---------------
last 7 days 298.77 MiB | 99.54 MiB | 398.31 MiB | 5.88 kbit/s
last week 294.88 MiB | 102.05 MiB | 396.93 MiB | 5.38 kbit/s
current week 125.38 MiB | 23.54 MiB | 148.92 MiB | 9.94 kbit/s
---------------------------+-------------+-------------+---------------
estimated 617 MiB | 113 MiB | 730 MiB |
OK.. now some internals ...you can actually clear the database and rebuild it at your will.So the steps are:
Step 10 : Clear the Database and rebuild it
sudo vnstat -r # for resetting the tool
then
sudo vnstat --rebuildtotal # Reset the total traffic counters and recount those using recorded months.
You can also specify which interface to monitor or not by passing an flag to it..
sudo vnstat --enable
OR
sudo vnstat --disable
But there is an option to extract out the database info ,which is called "--dumpdb"
lets get it from the man page :
Instead of showing the database with a formated output, this output will dump the whole database in a format that should be easy to parse with
most script languages. Use this for example with PHP, Perl or Python to make a custom webpage. The dump uses ; as field delimeter.
active;1 activity status
interface;eth0 name for the interface
nick;inet nick (if given)
created;1023895272 creation date in Unix time
updated;1065467100 when the database was updated
totalrx;569605 all time total received MiB
totaltx;2023708 all time total transmitted MiB
currx;621673719 latest rx value in /proc
curtx;981730184 latest tx value in /proc
totalrxk;644 total rx KiB counter
totaltxk;494 total tx KiB counter
btime;1059414541 system boot time in Unix time
Then follows 30 lines like the following
d;0;1078696800;559;7433;68;557;1
where d = days, 0 = day number in database (0 is today), 1077314401 date in Unix time, 559 = rx MiB, 7433 = tx MiB, 68 = rx KiB, 557 = tx KiB and
1 tells that vnStat has filled this value and it is in use.
m;0;1078092000;48649;139704;527;252;1 (x12)
t;0;1078351200;5979;47155;362;525;1 (x10)
h;0;1078699800;118265;516545 (x24)
m = months, t = top10 and h = hours, all other fields are in the same order as in days except hours that doesn't have a separate KiB value. For
hours the forth and fifth fields have values in KiB.
So it clearly stated it purpose.
Step 11: Top 10 traffic list
bhaskar@bhaskar-laptop_10:17:10_Tue Jul 20:~> sudo vnstat -t
ppp0 / top 10
# day rx | tx | total | avg. rate
-----------------------------+-------------+-------------+---------------
1 03/10/10 627.71 MiB | 33.10 MiB | 660.81 MiB | 62.65 kbit/s
2 04/16/10 344.85 MiB | 28.56 MiB | 373.40 MiB | 35.40 kbit/s
3 06/30/10 315.76 MiB | 51.66 MiB | 367.42 MiB | 34.84 kbit/s
4 05/06/10 312.34 MiB | 26.65 MiB | 338.99 MiB | 32.14 kbit/s
5 07/11/10 296.82 MiB | 32.26 MiB | 329.08 MiB | 31.20 kbit/s
6 04/24/10 300.84 MiB | 24.38 MiB | 325.22 MiB | 30.84 kbit/s
7 05/05/10 271.04 MiB | 23.46 MiB | 294.50 MiB | 27.92 kbit/s
8 05/04/10 265.08 MiB | 23.83 MiB | 288.91 MiB | 27.39 kbit/s
9 05/31/10 224.23 MiB | 22.86 MiB | 247.09 MiB | 23.43 kbit/s
10 04/30/10 213.40 MiB | 25.67 MiB | 239.07 MiB | 22.67 kbit/s
-----------------------------+-------------+-------------+---------------
Curious to know more? Check out the website of it and of course the man paged.
Hope this will help.
Cheers!
Bhaskar
No comments:
Post a Comment