一个检测应用状态的脚本

#!/bin/sh

#Description:       Check ICE3.0 State

#Last Update:       2014/06/11/01

WORKDIR=`pwd`

export REPORTDIR=$WORKDIR/`date "+%Y%m%d%H%M%S"`

export TG=`date "+%Y%m%d%H%M%S"`

export BEGIN=`date -d "-1 hour" "+%H:%M:%S"`

export END=`date "+%H:%M:%S"`

ECORE=2

OCORE=0

APPDIR=/opt/app/ice3.0

LOGDIR=/DataBase/ice3.0/log

DISDIR=$LOGDIR/disconnect

ERRDIR=$LOGDIR/error

SYSDIR=$LOGDIR/sys

MONDIR=$LOGDIR/monitor

ECCONF=$APPDIR/conf/com.umpay.ice.core.common.services.model.EcChannel.xml

GWCONF=$APPDIR/conf/com.umpay.ice.core.common.services.model.GwChannel.xml

REPORT=$REPORTDIR/report

RESH=$APPDIR/bin/line-report.sh

QUEDIR=$APPDIR/conf-share/MonitorConfig.xml

FTPHOST=""

FTPUSER=""

FTPPASS=""

#Initialization

#[ $UID -ne 0 ] && printf "You must use the root user to run this script !\n" && exit $ECORE

[ -d $REPORTDIR ] || mkdir -p $REPORTDIR

#[ -d $LOGDIR ] || exit $ECORE

#[ -d $APPDIR ] || exit $ECORE

#INITA

INITA()

{

printf "\n"

printf "\t\t\t Now time: `date "+%Y-%m-%d %H:%M"` \n"

printf "\n"

}

#Process Disk

PDISK()

{

printf "PROCE:\n"

JAVAPID=`ps aux|grep java|grep -v "grep java"|awk -v AP=$APPDIR ‘{if($12~AP) print $2}‘`

if [ -z $JAVAPID ];then

printf "\t\t\t Error NO Process  "

else

printf "\t\t\t OK Pid [$JAVAPID]"

fi

printf "\n"

#Disk

printf "\n"

printf "Disk:\n"

df -P |egrep -v "File|tmpfs" |sed ‘s/%//g‘|awk ‘

{if($5>90)

{print "\t\t\t"   " Error! "$6" \t Usage:"" " $5"%"}

else

{ print "\t\t\t"   " OK  "$6"  \t Usage:"" " $5"%"}

}‘

printf "\n"

}

#LOG

LOG(){

printf "\n"

printf "LOG:\n"

if [ -f $LOGDIR/log ];then

LSIZE1=`ls -l $LOGDIR/log |awk ‘{print $5}‘`

sleep 30

LSIZE2=`ls -l $LOGDIR/log |awk ‘{print $5}‘`

if [ $LSIZE2 -gt $LSIZE1 ];then

printf "\t\t\t OK SIZE $LSIZE2 > $LSIZE1 \n"

printf "\n"

else

printf "\t\t\t Error $LSIZE1 = $LSIZE2 \n"

printf "\n"

fi

else

printf "\t\t\t Error $LOGDIR/log File Not Found !"

printf "\n"

fi

}

#Ecport

ECPORT(){

printf "\n"

printf "EC Port Listen:\n"

if [ -f $ECCONF ];then

PORTNUM=`grep "port=" $ECCONF|awk ‘BEGIN{FS="="}{print $3}‘|sed -e ‘s/\&.*//g‘|wc -l`

if [ $PORTNUM -eq 2 ];then

ECPORT1=`grep "port=" $ECCONF|awk ‘BEGIN{FS="="}{print $3}‘|sed -e ‘s/\&.*//g‘|sed -n ‘1p‘`

ECPORT2=`grep "port=" $ECCONF|awk ‘BEGIN{FS="="}{print $3}‘|sed -e ‘s/\&.*//g‘|sed -n ‘2p‘`

if [ $ECPORT1 -eq $ECPORT2 ];then

export ALECPORT=$ECPORT1

netstat -nutl |awk ‘{print $4}‘|grep -q $ECPORT1

if [ $? -eq 0 ];then

printf "\t\t\t OK \t Port $ECPORT1 is Listening\n"

printf "\n"

else

printf "\t\t\t Error \t Port $ECPORT1 is not Listening  \n"

printf "\n"

fi

else

for i in `grep "port=" $ECCONF|awk ‘BEGIN{FS="="}{print $3}‘|sed -e ‘s/\&.*//g‘`

do

netstat -nutl |awk ‘{print $4}‘|grep -q $i

if [ $? -eq 0 ];then

printf "\t\t\t OK \tPort $i is Listening\n"

printf "\n"

else

printf "\t\t\t Error \tPort $i is not Listening  \n"

printf "\n"

fi

done

fi

elif [ $PORTNUM -eq 3 ];then

ECPORT1=`grep "port=" $ECCONF|awk ‘BEGIN{FS="="}{print $3}‘|sed -e ‘s/\&.*//g‘|sed -n ‘1p‘`

ECPORT2=`grep "port=" $ECCONF|awk ‘BEGIN{FS="="}{print $3}‘|sed -e ‘s/\&.*//g‘|sed -n ‘2p‘`

ECPORT3=`grep "port=" $ECCONF|awk ‘BEGIN{FS="="}{print $3}‘|sed -e ‘s/\&.*//g‘|sed -n ‘3p‘`

if [ $ECPORT1 -eq $ECPORT2 ] && [ $ECPORT1 -eq $ECPORT3 ];then

netstat -nutl |awk ‘{print $4}‘|grep -q $ECPORT1

if [ $? -eq 0 ];then

printf "\t\t\t OK \tPort $ECPORT1 is Listening\n"

printf "\n"

else

printf "\t\t\t Error \tPort $ECPORT1 is not Listening  \n"

printf "\n"

fi

elif [ $ECPORT1 -eq $ECPORT2 ] || [ $ECPORT2 -eq $ECPORT3 ];then

for i in $ECPORT1 $ECPORT3

do

netstat -nutl |awk ‘{print $4}‘|grep -q i

if [ $? -eq 0 ];then

printf "\t\t\t OK \tPort $i is Listening\n"

printf "\n"

else

printf "\t\t\t Error \tPort $i is not Listening  \n"

printf "\n"

fi

done

else

for i in `grep "port=" $ECCONF|awk ‘BEGIN{FS="="}{print $3}‘|sed -e ‘s/\&.*//g‘`

do

netstat -nutl |awk ‘{print $4}‘|grep -q $i

if [ $? -eq 0 ];then

printf "\t\t\t OK \tPort $i is Listening\n"

printf "\n"

else

printf "\t\t\t Error \tPort $i is not Listening  \n"

printf "\n"

fi

done

fi

else

for i in `grep "port=" $ECCONF|awk ‘BEGIN{FS="="}{print $3}‘|sed -e ‘s/\&.*//g‘`

do

netstat -nutl |awk ‘{print $4}‘|grep -q $i

if [ $? -eq 0 ];then

printf "\t\t\t OK Port $i is Listen\n"

printf "\n"

else

printf "\t\t\t Error Port $i is not Listening  \n"

printf "\n"

fi

done

fi

else

printf "\t\t\t Error\t Ec Conf File is Not Fond  \n"

fi

}

#B->M->G

BMG(){

#B->M

printf "\n"

printf "B->M Socket State: \n"

if [ -f $ECCONF ];then

if [ ! -z $ALECPORT ];then

netstat -ant|sed -e ‘1d‘|awk ‘{if($6~"ESTABLISHED") print $0}‘|awk ‘{print $4}‘|grep -q $ALECPORT

if [ $? -eq 0 ];then

ENUM=`netstat -ant|sed -e ‘1d‘|awk ‘{if($6~"ESTABLISHED") print $0}‘|awk ‘{print $4}‘|grep $ALECPORT|grep -v "127.0.0.1"|wc -l`

printf "\t\t\t OK\t B->M Local Port $ALECPORT is ESTABLISHED\n"

printf "\t\t\t $ENUM\t Links\n"

else

printf "\t\t\t Error\t B->M No Socket Link Local Port $ALECPORT\n"

fi

else

for i in `grep "port=" $ECCONF|awk ‘BEGIN{FS="="}{print $3}‘|sed -e ‘s/\&.*//g‘`

do

netstat -ant|sed -e ‘1d‘|awk ‘{if($6~"ESTABLISHED") print $0}‘|awk ‘{print $4}‘|grep -q $i

if [ $? -eq 0 ];then

ENUM=`netstat -ant|sed -e ‘1d‘|awk ‘{if($6~"ESTABLISHED") print $0}‘|awk ‘{print $4}‘|grep $i|grep -v "127.0.0.1"|wc -l`

printf "\t\t\t OK\t B->M Local Port $i is ESTABLISHED\n"

printf "\t\t\t $ENUM\t Links\n"

else

printf "\t\t\t Error\t B->M No Socket Link Local Port $i\n"

fi

printf "\n"

done

fi

else

printf "\t\t\t Error\t Ec Conf File is Not Fond\n"

fi

#M->G

printf "\n"

printf "M->G Socket State: \n"

if [ -f $GWCONF ];then

for i in `grep "port=" $GWCONF|sed -e ‘s/.*port=//g‘ -e ‘s/&.*//g‘`

do

netstat -ant|sed -e ‘1d‘|awk ‘{if($6~"ESTABLISHED") print $0}‘|awk ‘{print $5}‘|grep -q $i

if [ $? -eq 0 ];then

GWADD=`grep "host=" $GWCONF |sed -e ‘s/.*host=//g‘ -e ‘s/&amp.*//g‘`

GNUM=`netstat -ant|sed -e ‘1d‘|awk ‘{if($6~"ESTABLISHED") print $0}‘|awk -v ADD=$GWADD -v PO=$i ‘$5~ADD":"PO  {n++} END {print n+0}‘`

printf "\t\t\t OK \t M->G  Remort Port $i is ESTABLISHED \n"

printf "\t\t\t $GNUM \t Links\n"

else

printf "\t\t\t Error\t M->G No Socket Link Remort Port $i\n"

fi

done

printf "\n"

else

printf "\t\t\t Error\t GW Conf File is Not Fond \n"

fi

}

#DIS

DIS(){

printf "\n"

printf "Disconnect: \n"

DSDIR="$LOGDIR/disconnect"

if [ -f $DSDIR ];then

awk -v B=$BEGIN -v E=$END ‘$2>B && $2<E && $3=="EcChannel" {n++} END {print"\t\t\t" " EC Disconnect:\t" n+0 "\t1Hours"}‘ < $DISDIR

awk -v B=$BEGIN -v E=$END ‘$2>B && $2<E && $3=="GwChannel" {n++} END {print"\t\t\t" " GW Disconnect:\t" n+0 "\t1Hours"}‘ < $DISDIR

printf "\n"

else

printf "\t\t\t OK Disconnect Log File is Not Fond \n"

fi

}

#Que

QUE(){

printf "\n"

printf "Queue: \n"

printf "\n"

GWNUM=`grep mtspeed $GWCONF |sed -e ‘s/.*mtspeed="//g‘ -e ‘s/" mtperiod.*//g‘`

GWPERCEN=`grep "GWMQ objectName=" $QUEDIR |sed -e ‘s/.*alertProportion="//g‘ -e ‘s/">//g‘`

ECPERCEN=`grep "ECMQ objectName=" $QUEDIR |sed -e ‘s/.*alertProportion="//g‘ -e ‘s/">//g‘`

ECNUM1=`grep "queue size"  $ECCONF |sed -e ‘s/.*size="//g‘ -e ‘s/"\/>//g‘|sed -n ‘1p‘`

ECNUM2=`grep "queue size"  $ECCONF |sed -e ‘s/.*size="//g‘ -e ‘s/"\/>//g‘|sed -n ‘2p‘`

[ $ECNUM1 -eq $ECNUM2 ] && export ECNUM=$ECNUM1

QGW=`echo "scale=0;$GWNUM /100 * $GWPERCEN "|bc`

#echo $QGW

QEC=`echo "scale=0;$ECNUM /100 * $ECPERCEN "|bc`

printf "\t\t\t GW \tQUEUE \n"

printf "\n"

GQUEUENUM=`grep "Q-GwChannel" $MONDIR |tail -1 |awk -F "total" ‘{print NF-2}‘`

for i in `seq 0 $GQUEUENUM`

do

A=`expr $i + 1`

GWSIZE=`grep "Q-GwChannel-1" $MONDIR |tail -1 |sed -e ‘s/.*QueueMonitor://g‘ -e ‘s/\[//g‘ -e ‘s/\]//g‘|awk -v A=$A -F "Q-GwChanel-1|mem" ‘{print $A}‘|awk -F ":" ‘{print $NF}‘`

if [ $GWSIZE -lt $QGW ];then

printf "\t\t\t OK \tQ-GwChannel-1-$i Total:$GWSIZE\n"

else

printf "\t\t\t Error \tQ-GwChannel-1-$i Total:$GWSIZE\n"

fi

done

printf "\n"

printf "\t\t\t EC \tQUEUE \n"

printf "\n"

EQUEUENUM=`grep "Q-EcChannel" $MONDIR |tail -1 |awk -F "EcChannel" ‘{print NF-1}‘`

#echo $EQUEUENUM

for i in `seq 1 $EQUEUENUM`

do

SO=`expr $EQUEUENUM + 1`

A=`expr $i + 1`

ECSIZE=`grep "Q-EcChannel-1" $MONDIR |tail -1|sed -e ‘s/.*QueueMonitor://g‘ -e ‘s/\[//g‘ -e ‘s/\]//g‘|awk -v A=$A -F "Q-EcChannel-" ‘{print $A}‘|sed -e ‘s/.\://g‘`

if [ $ECSIZE -lt $QEC ];then

printf "\t\t\t OK \tQ-EcChannel-$EQUEUENUM \t$ECSIZE\n"

else

printf "\t\t\t Error \tQ-EcChannel-$EQUEUENUM \t$ECSIZE\n"

fi

EQUEUENUM=`expr $EQUEUENUM - 1`

done

#printf "\t\t\t $QGW\n"

#printf "\t\t\t $QEC\n"

printf "\n"

}

#MON

MON(){

printf "\n"

printf "Mon: \n"

printf "\n"

if [ -f $MONDIR ];then

tail -100 $MONDIR > $REPORTDIR/monitor

printf "\t\t\t 100 line to monitor file \n"

else

printf "\t\t\t Error Monitor File not found !\n"

fi

printf "\n"

}

#ERROR SYS LINE

ESYSLINE(){

printf "\n"

printf "ERR: \n"

printf "\n"

#ERROR

if [ -f $ERRDIR ];then

awk -v B="$BEGIN.0" -v E="$END.0" ‘$2>B && $2<E {print}‘ $ERRDIR > $REPORTDIR/error

printf "\t\t\t 1 hour before to error file \n"

else

printf "\t\t\t Error Error File not found !"

fi

printf "\n"

#SYS

printf "\n"

printf "SYS: \n"

printf "\n"

if [ -f $SYSDIR ];then

awk -v B="$BEGIN.0" -v E="$END.0" ‘$2>B && $2<E {print}‘ $SYSDIR > $REPORTDIR/sys

printf "\t\t\t 1 hour before to sys file \n"

else

printf "\t\t\t Error error SYS File not found !\n"

fi

printf "\n"

#LILE

printf "\n"

printf "Line_Report: \n"

printf "\n"

if [ -f $RESH ];then

/bin/sh $RESH

else

printf "\t\t\t Error File $RESH Not Found \n"

fi

}

#TGZ

TGZ(){

if [ -d $REPORTDIR ];then

tar czf $TG.tar.gz $TG

[ $? -eq 0 ] && rm -rf $TG

else

printf "\t\t\t REPORT Directory not found \n"

fi

}

#PUT

PUT(){

ftp -n<<EOF

open $FTPHOST

user $FTPUSER $FTPPASS

cd ~/

put $TG.tar.gz

close

bye

EOF

}

#TEM

TEM(){

#for((i>=$1;i<=$2;++i))

for i in `seq $1 $2`

do

tput sc

echo -ne  "Please Waiting ... ... $i%"

sleep 0.1

tput rc

((++i))

done

}

SUM=1

B=10

FUN=(INITA PDISK LOG ECPORT BMG DIS QUE MON ESYSLINE TGZ)

while [ $SUM -le 100 ];

do

for j in ${FUN[*]}

do

INVERT=`expr 100 / ${#FUN[*]}`

$j >>$REPORT

TEM $SUM $B

export B=`expr $B + $INVERT`

export SUM=`expr $SUM + $INVERT`

done

done

printf "\n"

printf "Done \n"

#EOF

#for i in INITA PRO DISK LOG ECPORT BMG DIS MON ESYSLINE TGZ

#do

# $i | read BE ED

# do

# for j in `seq $BE $ED`

# do

# $i

# tput sc

#         echo -ne  "Please Waiting ... .... $j%"

#         sleep 0.1

#         tput rc

#     ((j++))

# done

#         done

#printf "\n"

#printf "Done \n"

一个检测应用状态的脚本,布布扣,bubuko.com

时间: 2024-10-26 07:07:26

一个检测应用状态的脚本的相关文章

python3写的一个检测远程服务器端口脚本

分两部分:1 python脚本2 一个config.txt文件有机会在共享一下编译成exe的文件. 1.脚本#!/usr/bin/env pythonimport osimport sysimport socketimport msvcrt b = sys.platformarr=[]if 'win*' == b:config = sys.path[0] + '\config.txt'else:config = sys.path[0] + '/config.txt'file = open(con

CSRF进阶之打造一个检测CSRF漏洞的脚本

前言: 还记得之前所学的CSRF漏洞吧.因为没有对表单做好对应的漏洞 而造成的CSRF漏洞.学了这个漏洞后逐渐的了解.这个比较鸡助. 代码: import requests,tqdm,time,os,re logo=""" ◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇ ◇◇◇◇◇◇◇

python-门户应用状态检查脚本

本周用python实现了一个门户应用状态检查脚本. 主要作用是快速收集应用状态,自动收集预置checkpoint的状态,在出现异常时提升问题定位效率. 已实现以下功能: 1.进程核查 2.GC情况核查 3.峰值秒PV核查 4.TCP连接数核查 5.负载情况核查 6.system error话单核查 7.watchdog状态核查 8.存储使用率核查 9.error日志核查 主要难点: 1.python对shell命令执行结果的解析,因为需要判断是否正常,需要将数据解析成array或dictiona

线上一个简单检测Ping状态的邮件报警脚本

Step1.安装sendmail来发邮件 # yum -y install sendmail # /etc/init.d/sendmail start # chkconfig sendmail on Step2.安装邮件客户端 # yum -y install mutt 2.1添加发件人信息,如下 # vim /etc/Muttrc set charset="utf-8"           #设置发邮件编码 set envelope_from=yes set rfc2047_para

nagios检测cockroach、nomad、consul集群节点状态的脚本

在nagios中需要检测cockroach.nomad.consul服务集群节点状态的脚本,查看服务集群状态的命令是:1.consul查看群集节点状态的命令 .[[email protected] ~]# consul members Node Address Status Type Build Protocol DC Segmentcgw122.zencoo.com 192.168.196.122:8301 alive server 1.4.3 2 cd <all>cws113.zencoo

linux系统负载状态检查脚本

为了便于分析问题,编写了一个linux状态检查脚本,脚本可放置任意目录,脚本执行检测后会输出日志记录到当前目录下.直接执行脚本可用于一次检测,可通过日志进行分析.如果需要长时间监测,可执行-x参数,脚本会自动增加计划任务,并将日志输出到/tmp目录下.如果需要删除计划任务,可执行-xx参数. 脚本下载地址: wget http://jinxiang.oss-cn-hangzhou.aliyuncs.com/vmstatuscheck.sh #使用方法:  #例:./vmstatuscheck.s

[iOS 多线程 &amp; 网络 - 2.8] - 检测网络状态

A.说明 在网络应用中,需要对用户设备的网络状态进行实时监控,有两个目的:(1)让用户了解自己的网络状态,防止一些误会(比如怪应用无能)(2)根据用户的网络状态进行智能处理,节省用户流量,提高用户体验 WIFI\3G网络:自动下载高清图片 低速网络:只下载缩略图 没有网络:只显示离线的缓存数据 苹果官方提供了一个叫Reachability的示例程序,便于开发者检测网络状态https://developer.apple.com/library/ios/samplecode/Reachability

zabbix-2.0.8日常巡检-检测项目状态

在日常的监控运维中,因监控的内容较多,人较少的情况下,监控对本省的日常巡检成了一个重大的累赘(我们不可能每天对每一个检测项的状态进行检查,工作量,我的天呢),虽然我们可以使用zabbix自身报警,邮件等手段,但是,填写巡检表的时候,嘿嘿嘿,麻烦的让人想吐.监控自身巡检就成了必要的手段了. 由于时间问题和需求不定,我就暂将存在故障检测项的IP输出,未做处理(可以做成表格输出,大方,简洁,方便),还望抱歉. 前期准备: 1.修改zabbix的url,用户,密码 2.修改检测项目对应的key:keyi

Linux shell中getopts命令学习--实现一个添加yum源的脚本

getopts是bash shell的内建命令,作用是在shell脚本中解析命令行传递.传递给函数或传递给另一个调用的shell脚本的位置参数(选项或参数,后面会讲解,getopts只支持短选项,若要解析长选项请参考getopt). getopts命令语法: getopts optstring name [arg] 相关的术语: 选项(option):GNU风格的命令选项,如:-x,-y等减号加上单个字母的为短选项:--help为长选项: 选项的参数:某些选项之后必须尾随参数,如:-f xxx.