轻量级监控平台之监控脚本配置下发&定时任务启动
#!/bin/bash
#进程监控脚本
#功能需求: 轻量级监控平台下载ticket,帮助后续数据上报脚本完善入参
. /etc/profile
. ~/.bash_profile
pushurl="https://lightmonitorapi.test.cn/pull/ticket"
ip=$(ip addr | grep 'BROADCAST' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d '/')
msg=$(curl $pushurl \
-H "Accept: application/json" \
-H 'Content-Type: application/json' \
-d \ '{"ip": "'"${ip}"'", "ticket": "asdfasdf", "data": ""}')
cd /opt/shell/
sed -i "s/\r//" serviceCpu.sh
sed -i "s/\r//" serviceDisk.sh
sed -i "s/\r//" serviceGC.sh
sed -i "s/\r//" serviceProcess.sh
sed -i "s/\r//" serviceService.sh
sed -i "s/\r//" serviceThread.sh
croninfo=$(crontab -l)
if [ ! -n "$croninfo" ];then
echo "*/60 * * * * /bin/sh /opt/shell/serviceDisk.sh" >> conf && crontab conf && rm -f conf
crontab -l > conf && echo "*/1 * * * * /bin/sh /opt/shell/serviceCpu.sh" >> conf && crontab conf && rm -f conf
crontab -l > conf && echo "*/55 * * * * /bin/sh /opt/shell/serviceService.sh" >> conf && crontab conf && rm -f conf
crontab -l > conf && echo "*/10 * * * * /bin/sh /opt/shell/serviceProcess.sh" >> conf && crontab conf && rm -f conf
crontab -l > conf && echo "*/3 * * * * /bin/sh /opt/shell/serviceThread.sh" >> conf && crontab conf && rm -f conf
crontab -l > conf && echo "*/1 * * * * /bin/sh /opt/shell/serviceGC.sh" >> conf && crontab conf && rm -f conf
crontab -l > conf && echo "59 23 * * * /bin/sh /opt/shell/config.sh" >> conf && crontab conf && rm -f conf
crontab -l > conf && echo "*/1 * * * * /bin/sh /opt/shell/serviceError.sh" >> conf && crontab conf && rm -f conf
crontab -l > conf && echo "*/1 * * * * /bin/sh /opt/shell/serviceSlow.sh" >> conf && crontab conf && rm -f conf
crontab -l > conf && echo "*/10 * * * * /bin/sh /opt/shell/serviceMem.sh" >> conf && crontab conf && rm -f conf
echo "import shell to crontab success;"
else
shellinfo=$(echo "$croninfo" | grep "serviceDisk.sh")
if [ ! -n "$shellinfo" ];then
crontab -l > conf && echo "*/60 * * * * /bin/sh /opt/shell/serviceDisk.sh" >> conf && crontab conf && rm -f conf
fi
shellinfo=$(echo "$croninfo" | grep "serviceProcess.sh")
if [ ! -n "$shellinfo" ];then
crontab -l > conf && echo "*/10 * * * * /bin/sh /opt/shell/serviceProcess.sh" >> conf && crontab conf && rm -f conf
fi
shellinfo=$(echo "$croninfo" | grep "serviceCpu.sh")
if [ ! -n "$shellinfo" ];then
crontab -l > conf && echo "*/1 * * * * /bin/sh /opt/shell/serviceCpu.sh" >> conf && crontab conf && rm -f conf
fi
shellinfo=$(echo "$croninfo" | grep "serviceThread.sh")
if [ ! -n "$shellinfo" ];then
crontab -l > conf && echo "*/3 * * * * /bin/sh /opt/shell/serviceThread.sh" >> conf && crontab conf && rm -f conf
fi
shellinfo=$(echo "$croninfo" | grep "serviceGC.sh")
if [ ! -n "$shellinfo" ];then
crontab -l > conf && echo "*/1 * * * * /bin/sh /opt/shell/serviceGC.sh" >> conf && crontab conf && rm -f conf
fi
shellinfo=$(echo "$croninfo" | grep "config.sh")
if [ ! -n "$shellinfo" ];then
crontab -l > conf && echo "1 0 * * * /bin/sh /opt/shell/config.sh" >> conf && crontab conf && rm -f conf
fi
shellinfo=$(echo "$croninfo" | grep "serviceService.sh")
if [ ! -n "$shellinfo" ];then
crontab -l > conf && echo "*/55 * * * * /bin/sh /opt/shell/serviceService.sh" >> conf && crontab conf && rm -f conf
fi
shellinfo=$(echo "$croninfo" | grep "serviceError.sh")
if [ ! -n "$shellinfo" ];then
crontab -l > conf && echo "*/1 * * * * /bin/sh /opt/shell/serviceError.sh" >> conf && crontab conf && rm -f conf
fi
shellinfo=$(echo "$croninfo" | grep "serviceMem.sh")
if [ ! -n "$shellinfo" ];then
crontab -l > conf && echo "*/10 * * * * /bin/sh /opt/shell/serviceMem.sh" >> conf && crontab conf && rm -f conf
fi
shellinfo=$(echo "$croninfo" | grep "serviceSlow.sh")
if [ ! -n "$shellinfo" ];then
crontab -l > conf && echo "*/1 * * * * /bin/sh /opt/shell/serviceSlow.sh" >> conf && crontab conf && rm -f conf
fi
echo "import new shell file to crontab success;"
fi
chmod 755 serviceCpu.sh serviceDisk.sh serviceGC.sh serviceProcess.sh serviceService.sh serviceThread.sh serviceMem.sh serviceError.sh serviceSlow.sh serviceConfig.sh
echo "$msg" > /opt/shell/ticket.txt
架构设计@工程设计@服务稳定性之路