Controlando tráfego da rede com vnStat
Autor: Evandro Barreto | Publicado: 2007-08-31T01:12:00-03:00

O vnStat é um monitor de tráfego para Linux, podendo gerar relatórios de tráfego por hora, dia, mês, top10 e outros.Para instalar o vnStat no Ubuntu/Debian: sudo apt-get install vnstatPara dar as permissões aos usuários: sudo chmod o+x /usr/bin/vnstatsudo chmod o+wx /var/lib/vnstat/Feito isso, há a necessidade de se criar um job no cron para que o vnStat passe a coletar as informações de tráfego: vnstat -u -i ethxsubstituindo "x" pela id de sua interface (0, 1, etc)Agora execute o vnStat pelo console (é só digitar "vnstat" no prompt):$ vnstatDatabase updated: Mon Mar  8 22:15:00 2004inet (eth0)  received:      1,002,061 MB (24.6%)transmitted:      3,068,177 MB (75.4%)     total:      4,070,238 MB               rx     |     tx     |  total-----------------------+------------+-----------yesterday       335 MB |   6,881 MB |   7,216 MB   today     1,493 MB |   9,808 MB |  11,301 MB-----------------------+------------+-----------estimated     1,610 MB |  10,579 MB |  12,189 MB(com 2 interfaces)$ vnstat                 rx      /     tx      /    total    /  estimatedLocal (eth0): yesterday     7,564 MB  /   4,140 MB  /  11,704 MB     today        33 MB  /     112 MB  /     145 MB  /     195 MBInternet (eth1): yesterday       807 MB  /  12,361 MB  /  13,168 MB     today     1,079 MB  /     708 MB  /   1,787 MB  /   2,423 MB(listando os "top10"):$ vnstat -tinet (eth0)  #       day          rx      |     tx      |  total--------------------------------+-------------+-------------  1    10.02.04       1235 MB  |    2217 MB  |    3452 MB  2    01.03.04     923.66 MB  |    2138 MB  |    3061 MB  3    09.02.04        958 MB  |    1597 MB  |    2555 MB  4    07.02.04        976 MB  |    1316 MB  |    2292 MB  5    08.02.04       1064 MB  |     538 MB  |    1602 MB  6    05.02.04        772 MB  |     575 MB  |    1347 MB  7    02.03.04     291.16 MB  |  945.70 MB  |    1236 MB  8    06.02.04        480 MB  |     601 MB  |    1081 MB  9    03.03.04     237.72 MB  |  651.66 MB  |  889.38 MB 10    04.02.04        352 MB  |     454 MB  |     806 MB--------------------------------+-------------+-------------(tráfego diário):$ vnstat -dinet (eth0)   day         rx      |     tx      |  total------------------------+-------------+--------------  24.02.      4.38 MB  |    2.86 MB  |    7.24 MB  25.02.      2.51 MB  |    2.45 MB  |    4.97 MB  26.02.      2.42 MB  |    2.26 MB  |    4.69 MB  27.02.      2.29 MB  |    2.17 MB  |    4.47 MB  28.02.    199.82 MB  |   50.39 MB  |  250.21 MB  29.02.    262.74 MB  |  390.82 MB  |  653.56 MB  01.03.    923.66 MB  |   2,138 MB  |   3,061 MB  02.03.    291.16 MB  |  945.70 MB  |   1,236 MB  03.03.    237.72 MB  |  651.66 MB  |  889.38 MB  04.03.     13.92 MB  |  464.40 MB  |  478.32 MB  05.03.      2.28 MB  |    2.12 MB  |    4.40 MB  06.03.      2.26 MB  |    2.12 MB  |    4.39 MB  07.03.      2.26 MB  |    2.12 MB  |    4.39 MB  08.03.      2.37 MB  |    2.18 MB  |    4.55 MB------------------------+-------------+--------------estimated        2 MB  |       2 MB  |       4 MB(tráfego mensal):$ vnstat -m    inet (eth0)       month        rx      |       tx      |    total    ------------------------+---------------+---------------      Mar '03    15,959 MB  |    18,823 MB  |    34,782 MB      Apr '03    24,645 MB  |    20,440 MB  |    45,085 MB      May '03    31,314 MB  |    39,103 MB  |    70,417 MB      Jun '03    28,116 MB  |    42,988 MB  |    71,104 MB      Jul '03    27,552 MB  |    33,924 MB  |    61,476 MB      Aug '03    37,498 MB  |    38,189 MB  |    75,687 MB      Sep '03    19,750 MB  |    17,488 MB  |    37,238 MB      Oct '03     3,999 MB  |     4,492 MB  |     8,491 MB    ------------------------+---------------+---------------    estimated    18,479 MB  |    20,758 MB  |    39,237 MB(cálculo da média do tráfego):$ vnstat -tr10386 packets sampled in 5 secondsTraffic average for eth1  rx         112.21 kB/s            620 packets/s  tx        1444.77 kB/s           1456 packets/s(outros flags):vnstat --helpvnStat 1.4 by Teemu Toivola      -q, --query             query database     -h, --hours             show hours     -d, --days              show days     -m, --months            show months     -w, --weeks             show weeks     -t, --top10             show top10     -s, --short             use short output     -u, --update            update database     -i, --iface             change interface (default: eth0)     -?, --help              short help     -v, --version           show version     -tr, --traffic          calculate trafficSee also "--longhelp" for complete options list and "man vnstat".