>Есть сервак интернета на free и локальная сеть на x компов.
>Как сделать мониторинг трафика для каждого компа?
>Буду очень признателен если кто поможет! заранее блавгодарю!
Как вариант trafd и вот такой скрипт.
#!/bin/sh -xv
#
#
########## Vvodim peremennie #####################################
day="`date +%d-%m-%Y`"
year="`date +%Y`"
month="`date +%m`"
IpIn="192.168.0.254"
NetIn="192.168.0"
IpOut="195.90.159.122"
NewDir="/var/traffic/${year}/${month}"
######################################################################
mkdir -p ${NewDir}
cd ${NewDir}
########## Sohranyaem Statistiku po interfeysam ####################
/usr/local/bin/trafsave ed0
/usr/local/bin/trafsave fxp0
cat /dev/null > /var/log/traffic.log
/usr/local/bin/traflog -i ed0 -a -n -s >> ${NewDir}/summary.inet
cat /dev/null > /usr/local/var/trafd/trafd.ed0
/usr/local/bin/traflog -i fxp0 -a -n -s >> ${NewDir}/summary.lokalka
cat /dev/null > /usr/local/var/trafd/trafd.fxp0
########## Statistika LOCAL_NET-interfeysa #########################
grep "^${NetIn}" ${NewDir}/summary.lokalka > test_0
grep " ${IpIn} " test_0 > test_1
grep -v "^${NetIn}" ${NewDir}/summary.lokalka > test_2
grep "${NetIn}" test_2 >> test_1
>${NewDir}/lokalka.sum
>${NewDir}/tmp_file
i=1
while test $i != 254
do
grep " ${NetIn}.${i} " test_1 > test_3
cat test_3 | awk '
BEGIN { d=0 }
{
d=$NF+d
h=$3
}
END {
printf " %d \n",d
} ' > tmp_file
read tmp < tmp_file
byte=`expr ${tmp} + 1`
mbyte=`expr ${byte} / 1000000`
if [ ${mbyte} -ge 1 ]
then
echo "HOST ${NetIn}.${i} закачал ${mbyte} MB" >> ${NewDir}/lokalka.sum
else
echo "HOST ${NetIn}.${i} - net traffika"
fi
i=$(($i+1))
done
cat test_1 | awk '
BEGIN { d=1 }
{
d=$NF+d
}
END {
printf " %d \n",d
} ' > tmp_file
read tmp < tmp_file
byte=`expr ${tmp} + 1`
kbyte=`expr ${byte} / 1000`
mbyte=`expr ${byte} / 1000000`
if [ ${mbyte} -ge 1 ]
then
echo "Всего закачано: ${mbyte} MB" >> ${NewDir}/lokalka.sum
elif [ ${kbyte} -ge 1 ]
then
echo "Всего закачано ${kbyte} kB" >> ${NewDir}/lokalka.sum
else
echo "NET TRAFFIKA"
fi
########## Statistika INTERNET-interfeysa ##########################
grep ${IpOut} ${NewDir}/summary.inet > test1
cat test1 | grep " 80 " > test_HTTP
cat test1 | grep " 25 " > test_SMTP
cat test1 | grep " 21 " > test_FTP
cat test1 | grep " 20 " > test_FTP
cat test1 | awk '
BEGIN { d=0 }
{
d=$NF+d
}
END {
printf " %d \n",d
} ' > tmp_file
read tmp < tmp_file
byte=`expr ${tmp} + 1`
kbyte=`expr ${byte} / 1000`
mbyte=`expr ${byte} / 1000000`
if [ ${mbyte} -ge 1 ]
then
echo "Всего было входящего траффика: ${mbyte} MB" >> ${NewDir}/inet.sum
elif [ ${kbyte} -ge 1 ]
then
echo "Всего было входящего траффика: ${kbyte} kB" >> ${NewDir}/inet.sum
else
echo "NET TRAFFIKA"
fi
cat test_HTTP | awk '
BEGIN { d=0 }
{
d=$NF+d
}
END {
printf " %d \n",d
} ' > tmp_file
read tmp < tmp_file
byte=`expr ${tmp} + 1`
kbyte=`expr ${byte} / 1000`
mbyte=`expr ${byte} / 1000000`
if [ ${mbyte} -ge 1 ]
then
echo "По HTTP: ${mbyte} MB" >> ${NewDir}/inet.sum
elif [ ${kbyte} -ge 1 ]
then
echo "По HTTP: ${kbyte} kB" >> ${NewDir}/inet.sum
else
echo "NET TRAFFIKA"
fi
cat test_SMTP | awk '
BEGIN { d=0 }
{
d=$NF+d
}
END {
printf " %d \n",d
} ' > tmp_file
read tmp < tmp_file
byte=`expr ${tmp} + 1`
kbyte=`expr ${byte} / 1000`
mbyte=`expr ${byte} / 1000000`
if [ ${mbyte} -ge 1 ]
then
echo "По SMTP: ${mbyte} MB" >> ${NewDir}/inet.sum
elif [ ${kbyte} -ge 1 ]
then
echo "По SMTP: ${kbyte} kB" >> ${NewDir}/inet.sum
else
echo "NET TRAFFIKA"
fi
cat test_FTP | awk '
BEGIN { d=0 }
{
d=$NF+d
}
END {
printf " %d \n",d
} ' > tmp_file
read tmp < tmp_file
byte=`expr ${tmp} + 1`
kbyte=`expr ${byte} / 1000`
mbyte=`expr ${byte} / 1000000`
if [ ${mbyte} -ge 1 ]
then
echo "По FTP: ${mbyte} MB" >> ${NewDir}/inet.sum
elif [ ${kbyte} -ge 1 ]
then
echo "По FTP: ${kbyte} kB" >> ${NewDir}/inet.sum
else
echo "NET TRAFFIKA"
fi
########## GOTOVIM OT4ET ###########################################
> ${NewDir}/report
echo "============= Статистика локального интерфейса ===========" >> ${NewDir}/report
cat ${NewDir}/lokalka.sum >> ${NewDir}/report
echo "============= Стартистика внешнего интерфейса ============" >> ${NewDir}/report
cat ${NewDir}/inet.sum >> ${NewDir}/report
########## OTSILAEM PIS`MO ROOT`u ###################################
subj="Статистика_траффика_на_"${day}
mail -s ${subj} root < ${NewDir}/report
########## STIRAEM VREMENNIE FAILI #################################
rm -f test*
rm ${NewDir}/*.sum
rm ${NewDir}/report
rm ${NewDir}/tmp_file
З.Ы. Скрипт не мой, автора прошу не обижаться