轻量级监控平台之监控脚本配置下发

轻量级监控平台之监控脚本配置下发&定时任务启动

#!/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

架构设计@工程设计@服务稳定性之路

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值