侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

Network Equipment Traffic

2023-05-08 星期一 / 0 评论 / 0 点赞 / 84 阅读 / 3223 字

Definition read the file:[root@RHEL5 ~]# vi asptools/Report_Host Eth__0/0:30.30.30.1,Firewall,ifInOc

.

Definition read the file:
[root@RHEL5 ~]# vi asptools/Report_Host

Eth__0/0:30.30.30.1,Firewall,ifInOctets.1Eth__0/1:30.30.30.1,Firewall,ifInOctets.2Fast_0/0:172.17.25.250,CTP2,ifInOctets.1Ser0/0/0:172.17.24.250,HYQH.BJ,ifInOctets.7Ser0/0/1:172.17.24.250,HYQH.BJ,ifInOctets.8Fa___0/1:172.17.21.250,SH,ifInOctets.2Ser0/0/0:172.17.21.250,SH,ifInOctets.11Ser0/0/1:172.17.21.250,SH,ifInOctets.12Ser0/1/1:172.17.21.250,SH,ifInOctets.14Ser0/2/0:172.17.21.250,SH,ifInOctets.15Ser0/2/1:172.17.21.250,SH,ifInOctets.16Ser0/0/0:172.17.20.250,ZQ,ifInOctets.7Ser0/0/1:172.17.20.250,ZQ,ifInOctets.8Gi___0/1:172.17.22.250,ShuangLong,ifInOctets.3



Defined monitoring script:
[root@RHEL5 ~]# vi asptools/Report_traffic.sh

#!/bin/sh# Author: Kingcraft,20131104Flow_Monitor(){for line in $(<$Report_File)do        Ip=`echo $line | awk -F: '{print $2}' | awk -F, '{print $1}'`        Comm=`echo $line | awk -F: '{print $2}' | awk -F, '{print $2}'`        Int=`echo $line | awk -F: '{print $2}' | awk -F, '{print $3}'`        Int_name=`echo $line | awk -F: '{print $1}'`        COMMAND=`echo "snmpwalk -v 2c $Ip -c $Comm $Int"`        Counter1=`$COMMAND` 2>/dev/null        Traffic_a=`echo $Counter1 |awk -F: '{print $4}'` 2>/dev/null        sleep 1        Counter2=`$COMMAND` 2>/dev/null        Traffic_b=`echo $Counter2 |awk -F: '{print $4}'` 2>/dev/null        if [[ $Traffic_a -gt $Traffic_b  ]]        then                Traffic1=$(($Traffic_a - $Traffic_b))        else                Traffic1=$(($Traffic_b - $Traffic_a))        fi        KB=1024        if [[ $Traffic1 -eq 0 ]]        then                Traffic=0        elif [[ $Traffic1 -ge 1024 ]]        then                Traffic="`echo "scale=3;$Traffic1/$KB" | bc`" 2>/dev/null        else                Traffic="0`echo "scale=3;$Traffic1/$KB" | bc`" 2>/dev/null        fi        echo -e "$(date +%H:%M:%S)/t/t$Ip/t/t$Int_name/t/t$Traffic KB/s" >> $Dest_Path/Traffic.logdone}##########Main############Dest_Path=/root/asptools/logReport_File=/root/asptools/Report_HostFirst_time=$1Last_time=$2#Check the log directory exists and createif [[ ! -d $Dest_Path ]]then        mkdir -p $Dest_Pathfiif [[ $(date +%H%M) == "$First_time" ]]then        echo -e "/n" > $Dest_Path/Traffic.log        echo -e "/n" >> $Dest_Path/Traffic.log        echo -e "/t/t/t/txxxxxxxxx有限公司" >> $Dest_Path/Traffic.log        echo -e "/t/t/t/t日期:$(date +%Y-%m-%d)" >> $Dest_Path/Traffic.log        echo -e "/n" >> $Dest_Path/Traffic.log        echo -e "/n" >> $Dest_Path/Traffic.log        echo -e "Hour:Minute/t/tHOSTNAME/t/tInterface/t/tTraffic" >> $Dest_Path/Traffic.log        Flow_Monitor        sleep 60elif [[ $(date +%H%M) == "$Last_time" ]]then        Flow_Monitor        sleep 60fiexit 0




Defined monitoring script:
[root@RHEL5 ~]# crontab -e

* 9,13 * * * /root/asptools/Report_traffic.sh 0915 1345 >> /tmp/log


[root@RHEL5 ~]# service crond restart





.

广告 广告

评论区