MRTG当前流量排序scripts
V1.00 Created by Thomas(2004-12-30)
前言:
脚本在FreeBsd4.10上测试完成。于原文上的相关脚本(用于LINUX)做了相应修改。
参考:
http://www.net130.com/2004/6-22/224959.html
――使用MRTG监控网络信息流量
排序脚本(加到/etc/crontab中)
[code:1:387608836f]
#!/bin/sh
# MRTGSORT
#Create by Thomas 2004-12-30
#Just add to the end of MRTG sentence in /etc/crontab, example:;
#*/5 * * * * root /usr/local/bin/mrtg /usr/local/etc/mrtg/mrtg.cfg;/usr/local/etc/mrtg/mrtgsort.sh
#
#START....
#
>/tmp/tmp1
>/tmp/tmp2
>/tmp/tmp3
mrtgdir=/usr/local/www/data/mrtg
ls $mrtgdir/1/192*html>/tmp/tmp1
ls $mrtgdir/2/192*html>>/tmp/tmp1
for i in `cat /tmp/tmp1`
do
more $i|grep TITLE>>/tmp/tmp2
more $i|grep %
|cut -f4 -f5 -d" "
|awk 'NR==3{print}NR==6{print}'
|cut -f3 -d">" >>/tmp/tmp2
done
more /tmp/tmp2 | awk 'NR%3==1{printf("<tr><td> %s </td>",$0)}
NR%3==2{printf("<td> %s </td>",$0)}
NR%3==0{printf("<td> %s </td></tr>\n",$0)}'
|sed -e 's/<TITLE>//g' -e 's:;</TITLE>:;:;g' >/tmp/tmp3
echo -n '<HTML>
<HEAD>
<META content="TEXT/html; charset=gb2312" http-equiv=Content-Type>
</HEAD>
<BODY>
<p align=center><b>Sorted by current Input. (Unit KB) </b></p>
<table cellSpacing=0 cellPadding=1 width=600 align=center border=1>
<tr height=30 bgcolor=#FF9900>
<td >
<p>SwitchName&Port</p>
</td>
<td >
<p>InputSize</p>
</td>
<td >
<p>OutputSize</p>
</td>
</tr>
' >/usr/local/www/data/mrtg/1.html
echo -n '<HTML>
<HEAD>
<META content="TEXT/html; charset=gb2312" http-equiv=Content-Type>
</HEAD>
<BODY>
<p align=center><b>Sorted by current Output. (Unit KB) </b></p>
<table cellSpacing=0 cellPadding=1 width=600 align=center border=1>
<tr height=30 bgcolor=#00FFFF>
<td >
<p>SwitchName&Port</p>
</td>
<td >
<p>InputSize</p>
</td>
<td >
<p>OutputSize</p>
</td>
</tr>
' >/usr/local/www/data/mrtg/2.html
more /tmp/tmp3 | awk '{if ($7~/kb.*/) print}'|sort -t " " -rn +5 >>/usr/local/ww
w/data/mrtg/1.html
more /tmp/tmp3 | awk '{if ($7!~/kb.*/) print}'|sort -t " " -rn +5 >>/usr/local/w
ww/data/mrtg/1.html
more /tmp/tmp3 | awk '{if ($10~/kb.*/) print}'|sort -t " " -rn +8 >>/usr/local/w
ww/data/mrtg/2.html
more /tmp/tmp3 | awk '{if ($10!~/kb.*/) print}'|sort -t " " -rn +8 >>/usr/local/
www/data/mrtg/2.html
echo -n " </table>
</BODY>
</HTML>
">>/usr/local/www/data/mrtg/1.html
echo -n " </table>
</BODY>
</HTML>
">>/usr/local/www/data/mrtg/2.html