logoJulio Cardoso Tutoriais e Dicas


Monitorando consumo de banda on-line usando bwbar no debian

Postado em Linux (OS) Network(Servidores) Por julio em 19/09/08

Esse tutorial eu vou falar do bwbar que é um programa escrito em C mantido e pelo kernel.org .

Bem ele você pode ver pela web o consumo da banda de sua máquina ou server pela web .

Primeiro você vai precisar ter o apache com o php instalados . caso você queira instalar .

# apt-get install apache2 libapache2-mod-php4

Ele vai precisar de bibliotecas do png, então vamos instalar .

# apt-get install libpngwriter0c2 libpngwriter0-dev libpng12-dev libpng12-0 libpng3

Vamos instalar a biblioteca do gcc para compilarmos o programa .

# apt-get install g++

Vamos compilar o bwbar .

Entre no diretório /usr/src

# cd /etc/src
Vamos baixar o código mas recente nesse Site .

No console

# /usr/src# wget http://www.kernel.org/pub/software/web/bwbar/bwbar-1.2.3.tar.gz

# tar -xzvf bwbar-1.2.3.tar.gz

# cd bwbar-1.2.3

# gcc -c bwbar.c

# make

# cp bwbar /usr/sbin

Próxima parte.

Primeiro precisamos saber as interfaces de rede na máquina .

# ifconfig

~# ifconfig

eth1 Encapsulamento do Link: Ethernet Endereço de HW 00:19:5B:FC:D3:96
inet end.: 192.xx.xx.xx Bcast:192.xx.xx.xx Masc:255.255.0.0
endereço inet6: fe80::219:5bff:fefc:d396/64 Escopo:Link
UP BROADCASTRUNNING MULTICAST MTU:1500 Métrica:1
RX packets:12310558 errors:0 dropped:0 overruns:0 frame:0
TX packets:4714 errors:0 dropped:0 overruns:0 carrier:0
colisões:0 txqueuelen:1000
RX bytes:1303431423 (1.2 GiB) TX bytes:199104 (194.4 KiB)
IRQ:177 Endereço de E/S:0×9400

eth2 Encapsulamento do Link: Ethernet Endereço de HW 00:19:5B:84:9D:8C
inet end.: 200.xx.xx.xx Bcast:200.xx.xx.xx Masc:255.255.255.0
endereço inet6: fe80::219:5bff:fe84:9d8c/64 Escopo:Link
UP BROADCASTRUNNING MULTICAST MTU:1500 Métrica:1
RX packets:6382805 errors:0 dropped:0 overruns:0 frame:0
TX packets:18752659 errors:0 dropped:0 overruns:0 carrier:0
colisões:0 txqueuelen:1000
RX bytes:1953141592 (1.8 GiB) TX bytes:1277461012 (1.1 GiB)
IRQ:169 Endereço de E/S:0×9000

Então vamos criar o arquivo em php que vai ser usado para visualizarmos o consumo da banda .

No meu caso vou criar no diretório do apache /var/www/bwbar

Criar o diretório
# mkdir /var/www/bwbar

Entrar no diretório
#cd /var/www/bwbar

Criar o arquivo vazio
# touch index.php
Enditando o arquivo .

# nano index.php

vou colocar esse conteúdo

Mude o conteúdo de acordo com o seu cenário .

<html>
<head>
<title>Consumo de Banda</title>
<meta http-equiv=’refresh’ content=’2; URL=http://seu_IP/bwbar/index.php’>
</head>
<body>
<div align=”center”>
<font color=blue><h3>Interface eth2 - download</h3></font>
<?
readfile(”ubar_eth2_in.txt”);
?>
<br>
<img src=”ubar_eth2_in.png” border=”0″><br>
</div>

<div align=”center”>
<font color=blue><h3>Interface eth2 - upload</h3></font>
<?
readfile(”ubar_eth2_out.txt”);
?>
<br>
<img src=”ubar_eth2_out.png” border=”0″><br>
</div>

Baixe aqui esse código .

Bem para iniciarmos o programa.

cd /var/www/bwbar

bwbar -i eth2 1 -k -f ubar_eth2_in.txt -p ubar_eth2_in.png -t 1 &
bwbar -o eth2 1 -k -f ubar_eth2_out.txt -p ubar_eth2_out.png -t 1 &

Lembrando que você tem que alterar a interface de rede e os nomes dos arquivos de acordo com o seu cenário .

Comandos do bwbar

Options: (defaults in parenthesis)
–input -i Measure input bandwidth
–output -o Measure output bandwidth (default)
–text-file <file> -f The name of the text output file (ubar.txt)
–png-file <file> -p The name of the graphical bar file (ubar.png)
–interval <seconds> -t The poll interval in seconds (15)
–width <pixels> -x Width of the graphical bar (600)
–height <pixels> -y Height of the graphical bar (4)
–border <pixels> -b Border width of the graphical bar (1)
–kbps -k Bandwidth is measured in kbit/s
–Mbps -M Bandwidth is measured in Mbit/s (default)
–Gbps -G Bandwidth is measured in Gbit/s
–help -h Display this text

Pronto .

Deixe seu Comentário