其实就是一个ps进程探测,
后面写一个分析
文件先贴出来。
#! /bin/sh
###file_ver=2.0.3
PATH=$PATH:.
#monitor the application
#create by leonlaili,2006-12-6
####### Custom variables begin ########
##todo: add custom variables here
#get script path
dir_pre=$(dirname $(which $0))
####### Custom variables end ########
#load common functions
load_lib()
{
common_file=$dir_pre/common.sh
if [ -f $common_file ];then
. $common_file
fi
}
#check current user
check_user()
{
if [ "$user" != "`whoami`" ];then
echo "Only $user can execute this script"
exit 1
fi
}
#print help information
print_help()
{
##todo: output help information here
# echo ....
return
}
#check script parameters
check_params()
{
ok="true"
##todo: add addition parameters checking statement here...
if [ "$ok" != "true" ];then
echo "Some of the parameters are invalid. "
print_help
exit 1
fi
}
get_app_num()
{
numbers=`echo $app_name | sed -e "s:[ \t]:\n:g" | grep "^$1[:$]" | awk -F: '{print $2}'`
num1=`echo $numbers|awk -F, '{print $1}'`
num2=`echo $numbers|awk -F, '{print $2}'`
if [ "${num1}" = "" ];then
num1=1
fi
if [ "${num2}" = "" ];then
num2=999999999
fi
}
#check port
check_port()
{
nc_cmd="/usr/bin/nc"
if [ ! -f $nc_cmd ];then
nc_cmd="/usr/bin/netcat"
fi
$nc_cmd -zn -w4 $1 $2
if [ $? -ne 0 ];then
for (( i=0 ; i<5 ; i++ ))
do
$nc_cmd -zn -w4 $1 $2
if [ $? -eq 0 ];then return 0;fi
sleep 1
done
#check VIP again
if [ "$vip" != "" ];then
for (( i=0 ; i<5 ; i++ ))
do
$nc_cmd -zn -w4 $vip $2
if [ $? -eq 0 ];then return 0;fi
sleep 1
done
fi
err_port="$err_port $p"
return 1
fi
return 0
}
#check process
check_process()
{
get_app_num $1
app=`echo $1 | awk -F: '{print $1}'`
num=`ps -C $app | sed -e "1d" | wc -l`
if [ $num -lt $num1 -o $num -gt $num2 ];then
err_app="$err_app $app"
return 1
fi
return 0
}
#check if application is ok
check_app()
{
if [ ! -f $runing_file ];then
return 0
fi
if [ "$ip_type" = "0" ];then
bind_ip=$ip_inner
elif [ "$ip_type" = "1" ];then
bind_ip=$ip_outer
elif [ "$ip_type" = "2" ];then
bind_ip="0.0.0.0"
elif [ "$ip_type" = "3" ];then
bind_ip=$vip
elif [ "$ip_type" = "4" ];then
bind_ip=127.0.0.1
fi
##todo: add application checking statement here
err_app=""
err_port=""
run_config "monitor"
}
#resolve the problems of application
resolve_app()
{
#发送告警信息
report "Monitor: restart [process:${err_app}][port:${err_port}]"
##todo: add custom statement here
run_config "resolve"
return
}
#report monitor result infomation
rpt_info()
{
local rtype="$1"
local elem="$2"
local action="$3"
report_ip=172.16.211.50
url_head="http://$report_ip/pkg/monitor_rpt.php"
response_file="/tmp/.monitor_report.tmp"
wget_options="-T 10 -O $response_file --connect-timeout=5"
wget $wget_options "${url_head}?ip=${ip_inner}&install_path=${install_path}&type=${rtype}&elem=${elem}&action=${action}" > /dev/null 2>&1
rm $response_file 2>/dev/null
}
###### Main Begin ########
if [ "$1" = "--help" ];then
print_help
exit 0
fi
load_lib
check_user
check_params
check_app
if [ "$err_app" != "" -o "$err_port" != "" ];then
resolve_app
fi
if [ "$err_app" != "" ];then
err_app_list=`echo "$err_app" | sed -e 's/ /,/g' -e 's/^,//' -e 's/,$//'`
rpt_info 'app' "$err_app_list" "restart"
fi
if [ "$err_port" != "" ];then
err_port_list=`echo "$err_port" | sed -e 's/ /,/g' -e 's/^,//' -e 's/,$//'`
rpt_info 'port' "$err_port_list" "restart"
fi
###### Main End ########
framework_ver=2.0.7
<!--程序包基本信息-->
<base_info>
#程序作者
author="funnychen"
#所属产品
product="third"
#模块
module=""
#软件包名称
name="nginx"
#进程名不能超过15字符,多个进程空格间隔,可指定进程数量.app:min,max,如app_name:1,20
app_name="nginx"
#进程监听TCP端口!仅限TCP端口,多个端口使用空格间隔
port="80"
#TCP端口绑定ip类型!仅限TCP端口 0:内网;1:外网;2:0.0.0.0;3:VIP;4:127.0.0.1
ip_type="2"
#软件包版本
version="0.7.67"
#所属用户
user="root"
#停止进程信号量
kill_sig="KILL"
#是否开机启动[0|1]
auto_start="1"
#开机启动脚本存放文件
boot_path="/usr/local/services/etc/svc.sh"
#日志目录(日志直接存放在安装目录请设为空)
log_dir="/data/log/$name-$version"
#告警特性ID(默认不需要修改)
rpt_port="5570"
#基础安装目录(请勿修改)
install_base="/usr/local/services"
#系统使用变量请勿修改
install_path="/usr/local/services/nginx-0.7.67"
#是否强制在老目录安装(请勿修改)
force_install="false"
</base_info>
<!--安装时创建文件链接-->
<link>
cd $install_path
ln -s log logs
rm /usr/local/nginx 2>/dev/null
ln -s $install_path /usr/local/nginx
</link>
<!--程序启动方式,请使用相对bin目录的路径-->
<start>
#限制core文件大小为4k,用于进程coredump监控
ulimit -c 4 -S
ulimit -n 100001
#-----单进程名程序包请在这添加启动命令-----
./nginx
#-----多进程名程序包请在这添加启动命令-----
#每个进程复制一份if语句,注意保留if判断逻辑并修改内部的示例进程名app_test
#变量app_to_start为需要启动的进程名,不需要修改
#if [ "$app_to_start" = "app_test" -o "$app_to_start" = "all" ];then
# ./app_test &
#fi
</start>
<!--自定义crontab调度,请使用/usr/local/services/nginx-0.7.67占位符-->
<!--Example: "0 0 * * * /usr/local/services/nginx-0.7.67/admin/start.sh &" -->
<crontab>
*/3 * * * * /usr/local/services/nginx-0.7.67/admin/monitor.sh > /usr/local/services/nginx-0.7.67/log/crontab.log 2>&1 &
*/15 * * * * /usr/local/services/nginx-0.7.67/admin/clear.sh file > /usr/local/services/nginx-0.7.67/log/crontab.log 2>&1 &
15 8 * * * /usr/local/services/nginx-0.7.67/admin/md5sum.sh check > /usr/local/services/nginx-0.7.67/log/crontab.log 2>&1 &
0 0 * * * /usr/local/services/nginx-0.7.67/tools/log_clear.sh > /usr/local/services/nginx-0.7.67/log/log_clear.log 2>&1 &
</crontab>
<!--程序停止方式-->
<stop>
#停止进程后等待时间(秒)
sleep_count=1
#变量app_to_stop为需要启动的进程名
if [ $app_count -gt 1 -a "$app_to_stop" != "all" ];then
kill_app $app_to_stop $kill_sig
sleep $sleep_count
return
fi
for app_info in $app_name
do
app=`echo $app_info | awk -F: '{print $1}'`
kill_app $app $kill_sig
sleep $sleep_count
done
</stop>
<!--程序状态检测,若检测异常则添加异常进程名到err_app或添加异常端口到err_port-->
<monitor>
#进程数量检测
for app_info in `cat $runing_file`
do
check_process "$app_info"
done
#端口检测
for p in `echo $port`
do
check_port "$bind_ip" "$p"
done
</monitor>
<!--程序异常处理,根据状态检测是否正常决定-->
<resolve>
for app in `echo $err_app`
do
$install_path/admin/restart.sh $app
done
</resolve>
<!--需要进行md5校验的文件列表,请使用相对安装目录的路径,带"<空格>-"后缀为不需要进行校验-->
<md5>
bin/*
lib/*
admin/*
bin/*.pid -
bin/*core* -
bin/*.tmp -
bin/*.stat -
bin/*.log -
bin/*.data -
bin/*.dat -
bin/*.bin -
bin/*.info -
</md5>
<!--需要进行安装时替换内容的文件列表,请使用相对安装目录的路径-->
<substitute>
init.xml
conf/*
etc/*
</substitute>
<!--数据清理配置-->
<clear_file>
#目录 #阀值 #命令 #参数 #目标
log 85%:2000M tar 10 *.log
admin/data/backup 90%:50M tar 10 *
admin/data/tmp 90%:10M delete 1 *
#----说明-----
#目录:需要监控的目录,使用相对安装目录路径
#阀值:触发清理操作的条件[分区使用百分比:目录最大空间<M|m>]
#命令:delete(删除指定时间前文件),tar(压缩指定时间前文件),clear(清空超过指定大小文件)
#参数:delete,tar(默认天数,后缀h为小时,m为分钟),clear(文件大小k)
#目标:可以清理的文件,接受通配符
#----示例-----
#目录 #阀值 #命令 #参数 #目标
#log 80%:10M delete 30 stat*.log
#data 90%:10M tar 30 */*.dat
#log 90%:10M clear 50000 debug/err*.log
</clear_file>
<install_on_complete>
chown user_00.users $install_path/conf/*
</install_on_complete>
分享到:
相关推荐
keepalived监控nginx进程操作手册,解决系统的负载均衡
详细说明了windows服务器nginx+tomcat+mysql部署及配置(配置阿里云后台安全组,配置域名)很适合新手学习 附件中包含: 1.操作说明文档 2.操作录屏 3.安装所用到的软件安装包 1)Windows Server 2019 数据中心版 ...
如果服务器中nginx挂掉,我们如何第一时间启动它?人工重启?no。 该脚本定时检测nginx状态,挂机自动重启nginx。 如果服务器中nginx挂掉,我们如何第一时间启动它?人工重启?no。 该脚本定时检测nginx状态,...
国内用Nginx的比较多,Nginx的监控比较老的方案可能...用Prometheus进行nginx的监控可以自动的对相关server_name和upstream进行监控,你也可以自定义Prometheus的数据标签,实现对不同机房和不同项目的nginx进行监控。
安装SSL证书时,强行杀掉了Nginx的进程,就再也没起来: Restarting nginx daemon: nginxcat: /usr/local/nginx/logs/nginx.pid: No such file or directorykill: usage: kill [-s sigspec | -n signum | -sigspec] ...
python监控nginx upstrem状态,当发现nginx 后端down掉后会发送钉钉通知
一步步安装nginx搭建流媒体服务器的所有软件打包; nginx-1.8.0.tar.gz :应用服务器主程序 nginx_mod_h264_streaming-2.2.7.tar.gz :MP4流媒体支持模块。 openssl-1.0.1c.tar.gz :openssl库 pcre-7.9.tar.gz :...
Nginx_Active:当前活跃的客户端连接数 Nginx_Reading:正在执行读操作的连接数 Nginx_Writing:正在执行写操作的连接数 Nginx_Waiting:正在等待的连接数 Nginx_Accepts:NGINX接受的客户端连接数(包括Handled+Waiting) ...
zabbix监控之nginx模板
1.1Nginx 简介 Nginx (engine x) 是一个轻量级的、高性能的、基于 Http 的、反向代理服务器,静态 web ...国内大型的站点,例如百度、京东、新浪、网易、腾讯、淘宝等,都使用了 Nginx。 https://www.netcraft.com/
nginx配置文件修改保存,自动加载重启,并检查配置文件是否修改成功。 Windows下使用nginx,启动之后,再修改配置文件,无需命令重新加载,修改保存配置文件,实时更新nginx重启。
可以查出系统中所有nginx进程,直接kill进程,一键搞定他,
资源名称:Web服务器之Nginx详解内容简介: Nginx有两个基本功能,一个是作为Web服务器(在这篇博文中重点讲解),另一个是作为反向代理(在下面的博文中详细讲解)。下面我们就来演示具体配置。首先我们要做的就是配置...
linux下设置nginx为系统进程,进行快速的stop+start+restart操作。
nginx日志自动定时切割及清除脚本
服务器及nginx常见漏洞修复
集群聊天服务器(nginx tcp负载均衡模块、muduo网络库、基于发布-订阅的redis消息队列、mysql数据库) 集群聊天服务器(nginx tcp负载均衡模块、muduo网络库、基于发布-订阅的redis消息队列、mysql数据库) 集群聊天...
在各种服务器(nginx,apache,tomcat)上设置CORS跨域设置.zip
情景 由于公司内网有多台服务器的http服务要映射到公司外网静态IP,如果用路由的端口映射来做,就只能一台内网服务器的80端口映射到外网80端口,其他服务器的80端口只能...就起到了“根据域名自动转发到相应服务器的
windows上架设流媒体服务器,nginx+rtmp+obs推流+vlc拉流解决方案。 Nginx是一款轻量级的Web 服务器/反向代理服务器,nginx-rmtp-module是Nginx服务器的流媒体插件。nginx通过rtmp模块提供rtmp服务, obs推送一个rtmp...