ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Oracle系统在Linux环境下的监控shell(通过飞信接口发送告警信息)

Oracle系统在Linux环境下的监控shell(通过飞信接口发送告警信息)

原创 Linux操作系统 作者:guidba 时间:2012-05-22 10:23:12 0 删除 编辑
#!/bin/bash
#name:monitor.sh
#make by gui
 
sendMessage()
{
_HOST_NAME=`ifconfig|grep 150.0|awk '{print $2}'|sed 's/addr://g'`
_ALERT_MESSAGE=$1
NOWTIME=`date +%F-%H:%M`
}
 
diskCheck()
{
DISK_THRESHOLD=85
for x in `df -h | grep /dev | awk '{print $5 "-" $6 "-" $2 "-" $4}' | sed 's/%//g'`
do
    disk_status=(${x//"-"/" "})
    if [ ${disk_status[0]} -gt $DISK_THRESHOLD ]; then
    sendMessage "Disk Directory ${disk_status[1]} Warning: Threshold=$DISK_THRESHOLD% Disk_total=${disk_status[2]} Disk_used=${disk_status[3]} Alert_value=${disk_status[0]}%"
    fi
done
}
 
cpuCheck()
{
LOAD_THRESHOLD=6
cpu_num=`grep -c 'model name' /proc/cpuinfo`
load_15=`uptime | awk '{print $NF}'`
load_int=`echo $load_15 | cut -f 1 -d "."`
    if [ $load_int -gt $LOAD_THRESHOLD ]; then
    sendMessage "CPU Load Warning: Threshold=$LOAD_THRESHOLD Alert_value=$load_15"
    fi
}
 
swapCheck()
{
SWAP_THRESHOLD=0.8
DATA_TYPE=MB
swap_total=`free -m | grep Swap | awk '{print  $2}'`
swap_free=`free -m | grep Swap | awk '{print  $4}'`
swap_used=`free -m | grep Swap | awk '{print  $3}'`
swap_ratio=0`echo "scale=2;$swap_used/$swap_total" | bc`
    if [ `echo "$swap_ratio > $SWAP_THRESHOLD" | bc` -eq 1 ]; then
    echo $swap_ratio
    echo $SWAP_THRESHOLD
    sendMessage "SWAP Load Warning: Threshold=$SWAP_THRESHOLD Swap_total=$swap_total$DATA_TYPE Swap_used=$swap_used$DATA_TYPE Swap_free=$swap_free$DATA_TYPE Swap_ratio=$swap_ratio%"
    fi
}
 
listenerCheck()
{
listener_port=`netstat -ntlp | grep :1521`
listener_status=${#listener_port}
    if [ $listener_status -eq 0 ]; then
    sendMessage "Oracle Listener Port 1521 is Wrong."
    fi
}
 
dbCheck()
{
sid=$ORACLE_SID
pslist=`ps -ef | grep pmon`
#pslist=ora_pmon_orcl
db_pmon=`echo $pslist | grep ora_pmon_$sid`
db_status=${#db_pmon}
#echo $db_pmon
    if [ $db_status -eq 0 ]; then
    sendMessage "Oracle Instance SID=$sid is Down."
    fi
}
 
systemMonitor()
{
    login
    sys_date=`date +%H%M`
    date1=0000
    date2=0006
#    echo $sys_date
#    echo $(date +%H)
    if [ $sys_date -gt $date1 -a $sys_date -lt $date2 ]; then
        diskCheck
    else
 cpuCheck
        swapCheck
        listenerCheck
        dbCheck
    fi
    exit 0
}
systemMonitor

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26543620/viewspace-730573/,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有了~
下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2012-05-15

  • 博文量
    1
  • 访问量
    3951