Alarm system monitoring project
- Defining subscripts is the monitoring project
The first load.sh is necessary, because any machine has been defined in the main script to monitor the system load
[root@hf-01 mon]# cd shares/
[root@hf-01 shares]# pwd
/usr/local/sbin/mon/shares
[root@hf-01 shares]# vim load.sh
#! /bin/bash
##Writen by aming##
load=`uptime |awk -F 'average:' '{print $2}'|cut -d',' -f1|sed 's/ //g' |cut -d. -f1`
#计算系统负载
if [ $load -gt 10 ] && [ $send -eq "1" ]
then
echo "$addr `date +%T` load is $load" >../log/load.tmp
#这条命令的目的是为了发送日志
/bin/bash ../mail/mail.sh [email protected] "$addr\_load:$load" `cat ../log/load.tmp`
fi
echo "`date +%T` load is $load"
502.sh content (502 definitely needs a log), 502 involves an access log, and the access log is designed to a time
- Because the script monitoring main script is executed once a minute, so 502 monitoring, you must see the time and information of the access log 1 minute ago
[root@hf-01 shares]# vim 502.sh
#! /bin/bash
d=`date -d "-1 min" +%H:%M`
c_502=`grep :$d: $log |grep ' 502 '|wc -l`
#截取一分钟以前的时间
if [ $c_502 -gt 10 ] && [ $send == 1 ]; then
echo "$addr $d 502 count is $c_502">../log/502.tmp
/bin/bash ../mail/mail.sh $addr\_502 $c_502 ../log/502.tmp
#mail就是定义发送给谁,发送的主题,发送的内容
fi
echo "`date +%T` 502 $c_502"
disk.sh content (disk usage)
- disk, the idea is to look at the partitions one by one
[root@hf-01 shares]# vim disk.sh
#! /bin/bash
##Writen by aming##
rm -f ../log/disk.tmp
for r in `df -h |awk -F '[ %]+' '{print $5}'|grep -v Use`
#[ %]+ 以 多个,空格 或者 % 作为分隔符,+号表示一个或多个;因为系统默认是英文,所以grep -v Use 过滤掉的就是 已用
do
if [ $r -gt 90 ] && [ $send -eq "1" ]
then
echo "$addr `date +%T` disk useage is $r" >>../log/disk.tmp
fi
done
if [ -f ../log/disk.tmp ]
then
df -h >> ../log/disk.tmp
/bin/bash ../mail/mail.sh $addr\_disk $r ../log/disk.tmp
echo "`date +%T` disk useage is nook"
else
echo "`date +%T` disk useage is ok"
fi
- awk specify multiple delimiters
[root@hf-01 shares]# echo "12:aa#123bb:22#ww" |awk -F '[:#]' '{print $3}'
123bb
[root@hf-01 shares]# echo "12:aa#123bb:22#ww" |awk -F '[:#]' '{print NF}'
5
[root@hf-01 shares]# echo "12:aa#123bb:22##ww" |awk -F '[:#]' '{print NF}'
6
[root@hf-01 shares]# echo "12:aa#123bb:22##ww" |awk -F '[:#]+' '{print NF}'
5
[root@hf-01 shares]#