Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2477603
  • 博文数量: 225
  • 博客积分: 11622
  • 博客等级: 上将
  • 技术积分: 7358
  • 用 户 组: 普通用户
  • 注册时间: 2006-04-18 10:05
个人简介

我们的生活是多么美好呀!!!!

文章存档

2013年(2)

2012年(9)

2011年(59)

2010年(8)

2009年(35)

2008年(112)

分类: LINUX

2008-09-25 16:21:22

监控项目---流量控制模块

  流量控制模块相对于其它模块功能稍多,具体参数有:

    alarm_traffic_in_up 10  入流量上限报警阀值
    alarm_traffic_out_below 30  出流量下限报警阀值
    alarm_traffic_out_up 80  出流量上限报警阀值
    alarm_traffic_out_time_below 10 22  入流量上线报警时间区间
    alarm_traffic_times 3  流量报警次数

  流量取值即以IP为目录下的in out文件,由中心服务器取各服务器串值得出..脚本名为:

    Module_Traffic_Alarm.sh  内容如下:

      注:参数配置优先为各IP目录下alarm_conf目录下的个性参数配置,以参数名为文件名,内存参数值..默认配置为default.conf存所有参数默认值...每行二列分别为参数名,参数值...

      当连续到达报警次数后,脚本会启动报邮件/短信报警程序,即alarm.sh.由报警程序根据送来的报警串来选择报警优先级,及相关处理人..报警程序后文将介绍...

  #!/bin/sh
  if [ $# -ne 1 ];then
          /bin/echo "Usage: $0 IP"
          exit 1
  fi
 
  MONITOR_DIR=/performance_center/performance_monitor
  DEFAULT_CONF_DIR=$MONITOR_DIR/default_conf
  DATA_DIR=/cacti/idctraffic/hosttraffic
  CONF_DIR=$DEFAULT_CONF_DIR
  DATE=`date +%Y%m%d--%T`
 
  #check data validity
  IP=$1
  if [[ -f $DATA_DIR/$IP/out && -f $DATA_DIR/$IP/in ]];then
          CURRENTLY_TRAFFIC=`/bin/cat $DATA_DIR/$IP/out`
          CURRENTLY_TRAFFIC_IN=`/bin/cat $DATA_DIR/$IP/in`
  else
          /bin/echo $DATE "$IP traffic in or out is no data_file" >> $MONITOR_DIR/logs/Traffic_error.log
          $MONITOR_DIR/scripts/Alarm.sh "$IP traffic in or out is no data_file" 2>>$MONITOR_DIR/logs/Traffic_error.log 1>/dev/null
          exit 1
  fi
  if [[ $CURRENTLY_TRAFFIC -lt 0 || $CURRENTLY_TRAFFIC -gt 100 ]];then
          /bin/echo $DATE "$IP traffic_out is illegal $CURRENTLY_TRAFFIC M" >> $MONITOR_DIR/logs/Traffic_error.log
          #$MONITOR_DIR/scripts/Alarm.sh "$IP traffic is illegal $CURRENTLY_TRAFFIC M" 2>$MONITOR_DIR/logs/Traffic_error.log 1>/dev/null
          exit 1
  fi
 
  MD5_FILENAME_UP=`/bin/echo "$IP traffic_out is over" -n | /usr/bin/md5sum | /bin/awk '{print $1}'`
  MD5_FILENAME_BELOW=`/bin/echo "$IP traffic_out is low" -n | /usr/bin/md5sum | /bin/awk '{print $1}'`
  MD5_FILENAME_IN=`/bin/echo "$IP traffic_in is over" -n | /usr/bin/md5sum | /bin/awk '{print $1}'`
 
  #set conf
  if [ -d $DATA_DIR/$IP/alarm_conf ];then
          CONF_DIR=$DATA_DIR/$IP/alarm_conf
          if [ -f $CONF_DIR/alarm_traffic_times ];then
                  TRAFFIC_ALARM_TIMES=`/bin/cat $CONF_DIR/alarm_traffic_times`
          else
                  TRAFFIC_ALARM_TIMES=`/bin/cat $DEFAULT_CONF_DIR/default.conf | /bin/grep "alarm_traffic_times" | /bin/awk '{print $2}'`
          fi
          if [ -f $CONF_DIR/alarm_traffic_out_up ];then
                  TRAFFIC_ALARM_VALUE_UP=`/bin/cat $CONF_DIR/alarm_traffic_out_up`
          else
                  TRAFFIC_ALARM_VALUE_UP=`/bin/cat $DEFAULT_CONF_DIR/default.conf | /bin/grep "alarm_traffic_out_up" | /bin/awk '{print $2}'`
          fi
          if [ -f $CONF_DIR/alarm_traffic_out_below ];then
                  TRAFFIC_ALARM_VALUE_BELOW=`/bin/cat $CONF_DIR/alarm_traffic_out_below`
          else
                  TRAFFIC_ALARM_VALUE_BELOW=`/bin/cat $DEFAULT_CONF_DIR/default.conf | /bin/grep "alarm_traffic_out_below" | /bin/awk '{print $2}'`
          fi
          if [ -f $CONF_DIR/alarm_traffic_in_up ];then
                  TRAFFIC_ALARM_VALUE_IN=`/bin/cat $CONF_DIR/alarm_traffic_in_up`
          else
                  TRAFFIC_ALARM_VALUE_IN=`/bin/cat $DEFAULT_CONF_DIR/default.conf | /bin/grep "alarm_traffic_in_up" | /bin/awk '{print $2}'`
          fi
          if [ -f $CONF_DIR/alarm_traffic_out_time_below ];then
                  BELOW_TIME_UP=`/bin/cat $CONF_DIR/alarm_traffic_out_time_below | /bin/awk '{print $1}'`
                  BELOW_TIME_DOWN=`/bin/cat $CONF_DIR/alarm_traffic_out_time_below | /bin/awk '{print $2}'`
          else
                  BELOW_TIME_UP=`/bin/cat $DEFAULT_CONF_DIR/default.conf | /bin/grep "alarm_traffic_out_time_below" | /bin/awk '{print $2}'`
                  BELOW_TIME_DOWN=`/bin/cat $DEFAULT_CONF_DIR/default.conf | /bin/grep "alarm_traffic_out_time_below" | /bin/awk '{print $3}'`
          fi
  else
          TRAFFIC_ALARM_TIMES=`/bin/cat $DEFAULT_CONF_DIR/default.conf | /bin/grep "alarm_traffic_times" | /bin/awk '{print $2}'`
          TRAFFIC_ALARM_VALUE_UP=`/bin/cat $DEFAULT_CONF_DIR/default.conf | /bin/grep "alarm_traffic_out_up" | /bin/awk '{print $2}'`
          TRAFFIC_ALARM_VALUE_BELOW=`/bin/cat $DEFAULT_CONF_DIR/default.conf | /bin/grep "alarm_traffic_out_below" | /bin/awk '{print $2}'`
          TRAFFIC_ALARM_VALUE_IN=`/bin/cat $DEFAULT_CONF_DIR/default.conf | /bin/grep "alarm_traffic_in_up" | /bin/awk '{print $2}'`
          BELOW_TIME_UP=`/bin/cat $DEFAULT_CONF_DIR/default.conf | /bin/grep "alarm_traffic_out_time_below" | /bin/awk '{print $2}'`
          BELOW_TIME_DOWN=`/bin/cat $DEFAULT_CONF_DIR/default.conf | /bin/grep "alarm_traffic_out_time_below" | /bin/awk '{print $3}'`
  fi
 
  #alarm check
  if [ $CURRENTLY_TRAFFIC -gt $TRAFFIC_ALARM_VALUE_UP ];then
          if [ ! -f $MONITOR_DIR/alarm_info/$MD5_FILENAME_UP ];then
                  /bin/echo 1 > $MONITOR_DIR/alarm_info/$MD5_FILENAME_UP
                  /bin/echo "$IP traffic_out is over $TRAFFIC_ALARM_VALUE_UP:$CURRENTLY_TRAFFIC M" >> $MONITOR_DIR/alarm_info/$MD5_FILENAME_UP
          else
                  CUR_ALARM_TIMES_UP=`/bin/cat $MONITOR_DIR/alarm_info/$MD5_FILENAME_UP | /bin/sed -n '{1p}'`
                  CUR_ALARM_TIMES_UP=`/usr/bin/expr $CUR_ALARM_TIMES_UP + 1`
                  if [ $CUR_ALARM_TIMES_UP -ge $TRAFFIC_ALARM_TIMES ];then
                          $MONITOR_DIR/scripts/Alarm.sh "$IP traffic_out is over $TRAFFIC_ALARM_VALUE_UP:$CURRENTLY_TRAFFIC M" 2>$MONITOR_DIR/logs/Traffic_error.log 1>/dev/null &
                          /bin/rm -rf $MONITOR_DIR/alarm_info/$MD5_FILENAME_UP
                  else
                          /bin/echo $CUR_ALARM_TIMES_UP > $MONITOR_DIR/alarm_info/$MD5_FILENAME_UP
                          /bin/echo "$IP traffic_out is over $TRAFFIC_ALARM_VALUE_UP:$CURRENTLY_TRAFFIC M" >> $MONITOR_DIR/alarm_info/$MD5_FILENAME_UP
                  fi
          fi
  else
          if [ -f $MONITOR_DIR/alarm_info/$MD5_FILENAME_UP ];then
                  /bin/rm -rf $MONITOR_DIR/alarm_info/$MD5_FILENAME_UP
          fi
  fi
 
  if [ $CURRENTLY_TRAFFIC_IN -gt $TRAFFIC_ALARM_VALUE_IN ];then
          if [ ! -f $MONITOR_DIR/alarm_info/$MD5_FILENAME_IN ];then
                  /bin/echo 1 > $MONITOR_DIR/alarm_info/$MD5_FILENAME_IN
                  /bin/echo "$IP traffic_in is over $TRAFFIC_ALARM_VALUE_IN:$CURRENTLY_TRAFFIC_IN M" >> $MONITOR_DIR/alarm_info/$MD5_FILENAME_IN
          else
                  CUR_ALARM_TIMES_IN=`/bin/cat $MONITOR_DIR/alarm_info/$MD5_FILENAME_IN | /bin/sed -n '{1p}'`
                  CUR_ALARM_TIMES_IN=`/usr/bin/expr $CUR_ALARM_TIMES_IN + 1`
                  if [ $CUR_ALARM_TIMES_IN -ge $TRAFFIC_ALARM_TIMES ];then
                          $MONITOR_DIR/scripts/Alarm.sh "$IP traffic_in is over $TRAFFIC_ALARM_VALUE_IN:$CURRENTLY_TRAFFIC_IN M" 2>$MONITOR_DIR/logs/Traffic_error.log 1>/dev/null &
                          /bin/rm -rf $MONITOR_DIR/alarm_info/$MD5_FILENAME_IN
                  else
                          /bin/echo $CUR_ALARM_TIMES_IN > $MONITOR_DIR/alarm_info/$MD5_FILENAME_IN
                          /bin/echo "$IP traffic_in is over $TRAFFIC_ALARM_VALUE_IN:$CURRENTLY_TRAFFIC_IN M" >> $MONITOR_DIR/alarm_info/$MD5_FILENAME_IN
                  fi
          fi
  else
          if [ -f $MONITOR_DIR/alarm_info/$MD5_FILENAME_IN ];then
                  /bin/rm -rf  $MONITOR_DIR/alarm_info/$MD5_FILENAME_IN
          fi
  fi
 
  if [[ `/bin/date +%H | sed s/^0//g` -lt $BELOW_TIME_UP || `/bin/date +%H | sed s/^0//g` -ge $BELOW_TIME_DOWN ]];then
          exit 0
  fi
 
  if [ $CURRENTLY_TRAFFIC -lt $TRAFFIC_ALARM_VALUE_BELOW ];then
          if [ ! -f $MONITOR_DIR/alarm_info/$MD5_FILENAME_BELOW ];then
                  /bin/echo 1 > $MONITOR_DIR/alarm_info/$MD5_FILENAME_BELOW
                  /bin/echo "$IP traffic_out is low $TRAFFIC_ALARM_VALUE_BELOW:$CURRENTLY_TRAFFIC M" >> $MONITOR_DIR/alarm_info/$MD5_FILENAME_BELOW
          else
                  CUR_ALARM_TIMES_BELOW=`/bin/cat $MONITOR_DIR/alarm_info/$MD5_FILENAME_BELOW | /bin/sed -n '{1p}'`
                  CUR_ALARM_TIMES_BELOW=`/usr/bin/expr $CUR_ALARM_TIMES_BELOW + 1`
                  if [ $CUR_ALARM_TIMES_BELOW -ge $TRAFFIC_ALARM_TIMES ];then
                          $MONITOR_DIR/scripts/Alarm.sh "$IP traffic_out is low $TRAFFIC_ALARM_VALUE_BELOW:$CURRENTLY_TRAFFIC M" 2>$MONITOR_DIR/logs/Traffic_error.log 1>/dev/null &
                          /bin/rm -rf $MONITOR_DIR/alarm_info/$MD5_FILENAME_BELOW
                  else
                          /bin/echo $CUR_ALARM_TIMES_BELOW > $MONITOR_DIR/alarm_info/$MD5_FILENAME_BELOW
                          /bin/echo "$IP traffic_out is low $TRAFFIC_ALARM_VALUE_BELOW:$CURRENTLY_TRAFFIC M" >> $MONITOR_DIR/alarm_info/$MD5_FILENAME_BELOW
                  fi
          fi
  else
          if [ -f $MONITOR_DIR/alarm_info/$MD5_FILENAME_BELOW ];then
                  /bin/rm -rf  $MONITOR_DIR/alarm_info/$MD5_FILENAME_BELOW
          fi
  fi
 
  exit 0

阅读(1437) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~