如何監控流量 - Linux

By Isabella
at 2011-09-17T23:19
at 2011-09-17T23:19
Table of Contents
如果你只是要簡單的流量監控
我最近幫公司寫了個簡單的script您可以參考看看
使用方法是幫此shell script下個名子(廢話..)
執行shell script後面參數($1)接您要監控的network interface
預設是3秒秀一次,請依需要修改(sleep後以及RESULT裡的數字)
用法是 : 譬如我主要是監控我server的bond1 interface就用
#sh shell bond1
修改一下也可以用來監控所有的interface,基本上有很大的拓展空間
就看您的需求自行修改
附帶一提的是我把info又另外導到./下的FTP.log(是為了測server FTP 流量)
不需要的話把echo後PIPE後面的連PIPE都拿掉就不會留下log
#cat NetFlowCheck.sh
#!/bin/bash
INTERFACE=$1
while true
do
input1=`cat /proc/net/dev | grep ${INTERFACE} | awk '{ print $1 }' | awk
-F":" '{ print $2 }'`
output1=`cat /proc/net/dev | grep ${INTERFACE} | awk '{ print $9 }'`
sleep 3
input2=`cat /proc/net/dev | grep ${INTERFACE} | awk '{ print $1 }' | awk
-F":" '{ print $2 }'`
output2=`cat /proc/net/dev | grep ${INTERFACE} | awk '{ print $9 }' `
inputALL=$(( ${input2} - ${input1} ))
outputALL=$(( ${output2} - ${output1} ))
inputRESULT=$(( ${inputALL} / 3 / 1024 ))
outputRESULT=$(( ${outputALL} / 3 / 1024))
echo "==============" | tee -a ./FTP.log
echo "INPUT : ${inputRESULT} KB/s" | tee -a ./FTP.log
echo ""
echo "OUTPUT : ${outputRESULT} KB/s" | tee -a ./FTP.log
done
※ 引述《chan15 (ChaN)》之銘言:
: http://imm.io/96eG
: The Social Network 裡面
: Mark 有用指令觀看網站流量
: 爬 Google 以後發現 iftop 這個套件
: 但畫面看起來好像也不太相同
: 請問有什麼方式可以使用呢?
--
我最近幫公司寫了個簡單的script您可以參考看看
使用方法是幫此shell script下個名子(廢話..)
執行shell script後面參數($1)接您要監控的network interface
預設是3秒秀一次,請依需要修改(sleep後以及RESULT裡的數字)
用法是 : 譬如我主要是監控我server的bond1 interface就用
#sh shell bond1
修改一下也可以用來監控所有的interface,基本上有很大的拓展空間
就看您的需求自行修改
附帶一提的是我把info又另外導到./下的FTP.log(是為了測server FTP 流量)
不需要的話把echo後PIPE後面的連PIPE都拿掉就不會留下log
#cat NetFlowCheck.sh
#!/bin/bash
INTERFACE=$1
while true
do
input1=`cat /proc/net/dev | grep ${INTERFACE} | awk '{ print $1 }' | awk
-F":" '{ print $2 }'`
output1=`cat /proc/net/dev | grep ${INTERFACE} | awk '{ print $9 }'`
sleep 3
input2=`cat /proc/net/dev | grep ${INTERFACE} | awk '{ print $1 }' | awk
-F":" '{ print $2 }'`
output2=`cat /proc/net/dev | grep ${INTERFACE} | awk '{ print $9 }' `
inputALL=$(( ${input2} - ${input1} ))
outputALL=$(( ${output2} - ${output1} ))
inputRESULT=$(( ${inputALL} / 3 / 1024 ))
outputRESULT=$(( ${outputALL} / 3 / 1024))
echo "==============" | tee -a ./FTP.log
echo "INPUT : ${inputRESULT} KB/s" | tee -a ./FTP.log
echo ""
echo "OUTPUT : ${outputRESULT} KB/s" | tee -a ./FTP.log
done
※ 引述《chan15 (ChaN)》之銘言:
: http://imm.io/96eG
: The Social Network 裡面
: Mark 有用指令觀看網站流量
: 爬 Google 以後發現 iftop 這個套件
: 但畫面看起來好像也不太相同
: 請問有什麼方式可以使用呢?
--
Tags:
Linux
All Comments
Related Posts
用unetbootin製作leeenux的問題

By Yuri
at 2011-09-16T22:23
at 2011-09-16T22:23
系統突然完全不能動

By Doris
at 2011-09-16T22:16
at 2011-09-16T22:16
ubuntu one

By Quintina
at 2011-09-16T17:29
at 2011-09-16T17:29
yum 的防火牆設定

By Brianna
at 2011-09-16T17:14
at 2011-09-16T17:14
架設DHCP時遇到的問題

By Harry
at 2011-09-16T15:29
at 2011-09-16T15:29