一、配置文件脚本
##to config the options if to monitor
##定义mysql的服务器地址、端口以及user、password
to_mon_cdb=0 ##0 or 1,default 0,0 not monitor, 1 monitor
db_ip=10.20.3.13
db_port=3315
db_user=username
db_pass=passwd
##httpd 如果是1则监控,为0不监控
to_mon_php_soket=0
##http_code_502 需要自定义访问日志路径以及域名
to_man_502=1
logfile=/date/log/xxx.xxx.com/cacess.log
##request_count 定义日志路径以及域名
to_man-request_count=0
req_log=/data/log/www.discuz.net/access.log
domainname=www.discuz.net
二、告警系统监控项目子脚本
load.sh的内容
#!/bin/bash
##Writen by aming##
load= `uptime |awk -F'averafe:' 'print $2' | cut -d '.' -f1|sed 's/ //g'|cut -d. f1 `
#过滤出系统负载值
if [ $load -gt 10 ] && [ $sed -eq "1" ]
then
echo "$addr `date +%T` load is $load" > ../log/load.tmp
/bin/bash ../mail/mail.sh $addr\_load $load ../log/load.tmp
fi
echo "`date +%T` load is $load"
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
fi
echo " ` date+%T` 502 $c_502"
disk.sh的 内容
#!/bin/bash
##Writen by aming#
rm -f ../log/disk.tmp
for r in ` df-h | awk -F '[ %]+' '{print $5}'`
disk.sh
#!/bin/bash
##Writen by aming#
rm -f ./log/disk.tmp
for r in `df -h | awk -F '[%]+' '{print $5}' | grep -v Use`
awk可以用多个分隔符,这里的分隔符为空格和%,同时存在都生效。
do
if [ $r -gt 90] &&[ $sed -eq "1"]
then
echo "$addr `date +%T` disk userage is $r " >> ../log/disk.tmp
fi
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 userage is nook"
else
echo "`date+%T` disk userage is ok"
fi
mail.sh
#!/bin/bash
##Writen by aming#
log=$1
t_s=`date +%s`
t_s=`date -d "2hours ago" +%s`
if [ ! -f /tmp/$log ]
then
echo $t_2 > /tmp/$log
fi
t_s2= tail -l /tmp/$log|awk '{print $1}'
echo $t_s >>/tmp/$log
v=$[$t_s-$t_s2]
echo $v
if [ $v -gt 3600 ]
then
./mail.py $1 $2 $3
echo "0" > /tmp/$log.txt
else
if [ ! -f /tmp/$log.txt ]
then
echo "0" >/tmp/$log.txt
fi
nu= cat /tmp/$log.txt
nu2=$[$nu+1]
echo $nu2>/tmp/$log.txt
if [ $nu2 -gt 10 ]
then
./mail.py $1 "trouble continue 10 mian $2" "$3"
fi
fi
以上主要为监控项目的一些代码记录