我们的生活是多么美好呀!!!!
全部博文(225)
分类: LINUX
2008-09-25 16:20:34
监控项目---磁盘Memory模块
磁盘IO模块涉及到的参数有:
alarm_memory_up 20 可用内存的利用率%
alarm_memory_times 3 报警次数
Memory一共用到三个数据文件,分别为:mem_buffer mem_cache mem_free mem_total 利用率计算
(buffer+cache+free)*100/total 取整跟alarm_memory_up比较..连续三次不足报警..
脚本名:Module_Memory_Alarm.sh 内容如下:
其它模块报警算法皆类似于此二模块,在此不作介绍了..如:LOAD CPU HTTP SQUID等及一些服务状况监控...
#!/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
#check data validity
IP=$1
if [[ -f $DATA_DIR/$IP/mem_buffer && -f $DATA_DIR/$IP/mem_cache && -f $DATA_DIR/$IP/mem_free && -f $DATA_DIR/$IP/mem_total ]];then
CURRENTLY_MEM_BUFFER=`/bin/cat $DATA_DIR/$IP/mem_buffer`
CURRENTLY_MEM_CACHE=`/bin/cat $DATA_DIR/$IP/mem_cache`
CURRENTLY_MEM_FREE=`/bin/cat $DATA_DIR/$IP/mem_free`
CURRENTLY_MEM_TOTAL=`/bin/cat $DATA_DIR/$IP/mem_total`
else
/bin/echo $DATE "$IP memory idle is no data_file" >> $MONITOR_DIR/logs/Memory_error.log
$MONITOR_DIR/scripts/Alarm.sh "$IP memory idle is no data_file" 2>>$MONITOR_DIR/logs/Memory_error.log 1>/dev/null
exit 1
fi
CURRENTLY_MEMORY=`/bin/echo $CURRENTLY_MEM_BUFFER $CURRENTLY_MEM_CACHE $CURRENTLY_MEM_FREE $CURRENTLY_MEM_TOTAL| awk '{printf "%d", ($1+$2+$3)*100/$4}'`
MD5_FILENAME_MEMORY=`/bin/echo "$IP memory idle is lack" -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_memory_times ];then
MEMORY_ALARM_TIMES=`/bin/cat $CONF_DIR/alarm_memory_times`
else
MEMORY_ALARM_TIMES=`/bin/cat $DEFAULT_CONF_DIR/default.conf | /bin/grep "alarm_memory_times" | /bin/awk '{print $2}'`
fi
if [ -f $CONF_DIR/alarm_memory_up ];then
MEMORY_ALARM_VALUE_UP=`/bin/cat $CONF_DIR/alarm_memory_up`
else
MEMORY_ALARM_VALUE_UP=`/bin/cat $DEFAULT_CONF_DIR/default.conf | /bin/grep "alarm_memory_up" | /bin/awk '{print $2}'`
fi
else
MEMORY_ALARM_TIMES=`/bin/cat $DEFAULT_CONF_DIR/default.conf | /bin/grep "alarm_memory_times" | /bin/awk '{print $2}'`
MEMORY_ALARM_VALUE_UP=`/bin/cat $DEFAULT_CONF_DIR/default.conf | /bin/grep "alarm_memory_up" | /bin/awk '{print $2}'`
fi
#alarm check
if [ $CURRENTLY_MEMORY -lt $MEMORY_ALARM_VALUE_UP ];then
if [ ! -f $MONITOR_DIR/alarm_info/$MD5_FILENAME_MEMORY ];then
/bin/echo 1 > $MONITOR_DIR/alarm_info/$MD5_FILENAME_MEMORY
/bin/echo "$IP memory idle is lack $MEMORY_ALARM_VALUE_UP:$CURRENTLY_MEMORY" >> $MONITOR_DIR/alarm_info/$MD5_FILENAME_MEMORY
else
CUR_ALARM_TIMES_MEMORY=`/bin/cat $MONITOR_DIR/alarm_info/$MD5_FILENAME_MEMORY | /bin/sed -n '{1p}'`
CUR_ALARM_TIMES_MEMORY=`/usr/bin/expr $CUR_ALARM_TIMES_MEMORY + 1`
if [ $CUR_ALARM_TIMES_MEMORY -ge $MEMORY_ALARM_TIMES ];then
$MONITOR_DIR/scripts/Alarm.sh "$IP memory idle is lack $MEMORY_ALARM_VALUE_UP:$CURRENTLY_MEMORY" 2>$MONITOR_DIR/logs/Memory_error.log 1>/dev/null &
/bin/rm -rf $MONITOR_DIR/alarm_info/$MD5_FILENAME_MEMORY
else
/bin/echo $CUR_ALARM_TIMES_MEMORY > $MONITOR_DIR/alarm_info/$MD5_FILENAME_MEMORY
/bin/echo "$IP memory idle is lack $MEMORY_ALARM_VALUE_UP:$CURRENTLY_MEMORY" >> $MONITOR_DIR/alarm_info/$MD5_FILENAME_MEMORY
fi
fi
else
if [ -f $MONITOR_DIR/alarm_info/$MD5_FILENAME_MEMORY ];then
/bin/rm -rf $MONITOR_DIR/alarm_info/$MD5_FILENAME_MEMORY
fi
fi
exit 0