进程pid判断脚本

2023-05-19 17:25:57 浏览数 (2)

# zabbix监控进程变动

业务需求后端进程宕机以后能在短时间内迅速拉起,业务影响不大,但是开发需要查看coredump,要求能监控到pid变化;在现有构架下zabbix能监控并报警;

在每台服务器/etc/zabbix/zabbix_agentd.conf设置路径:此例只需要piddiff.sh

UserParameter=checkpid,sh /usr/local/script/piddiff.sh

/etc/zabbix/sh下面存放脚本

storage为业务监控的id取值根据业务需求

代码语言:javascript复制
#!/bin/bash
onl_ok=1
onl_cored=3
dir=/etc/zabbix/sh
if [[ ! -f "$dir/old.txt" ]];then
    ps aux | grep storage | grep -v grep |grep -v probe | grep root | awk '{print $2,$11}' > $dir/old.txt
else
    sleep 1s
fi
    ps aux | grep storage | grep -v grep |grep -v probe | grep root | awk '{print $2,$11}' > $dir/now.txt
if ! diff -q $dir/old.txt $dir/now.txt > /dev/null;then
    echo $onl_cored
    diff -c $dir/old.txt $dir/now.txt > $dir/`date " %Y%m%d%H%M"`_diff.txt
    cat $dir/now.txt > $dir/old.txt
else
    echo $onl_ok
fi

0 人点赞