shell脚本监控服务进程,发送钉钉

1.首先创建钉钉机器人获取到webhook。

2.根据脚本更改自己需求要监控的服务进程即可。

#!/bin/bash
#定义钉钉接口
dingding_webhook="这里钉钉获取的Webhook"
#监控的某个进程这里把需要监控的在grep中替换即可 
process_count=$(ps aux | grep "php think queue:work --timeout 0" | grep -v grep | wc -l)
if [ $process_count -eq 0 ]; then
# message里面自己定义告警的内容
    message="生产服务器进程告警 'php think queue:work --timeout 0' 不存在,请检查!"
elif [ $process_count -gt 1 ]; then
    message="生产服务器存在多个进程告警 'php think queue:work --timeout 0',请检查!"
fi
#将监控的内容通过钉钉发送到群
if [ ! -z "$message" ]; then
    curl $dingding_webhook -H 'Content-Type: application/json' -d "{\"msgtype\": \"text\", \"text\": {\"content\": \"$message\"}}"
fi

3.最后加入定时脚本进行监控 根据需求,例如我这个2分钟监控一次

# crontab -e

*/2 * * * * /bin/bash /root/lien_php.sh

4.看下效果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值