zabbix監控業務進程變動
阿新 • • 發佈:2018-02-23
mil cor zab 進程 技術分享 ash itl 需要 12px Zabbix 監控進程宕機
業務需求後端進程宕機以後能在短時間內迅速拉起,業務影響不大,但是開發需要查看coredump,要求能監控到pid變化;在現有構架下zabbix能監控並報警;
當然zabbix設置報警設置就不再一一
在每臺服務器/etc/zabbix/zabbix_agentd.conf設置路徑:此例只需要piddiff.sh
UserParameter=checkpid,sh /usr/local/script/piddiff.sh
UserParameter=test,sh /usr/local/script/test.sh
UserParameter=discovery.process,/usr/local/script/disprocess.sh
UserParameter=process.check[*],/usr/local/script/proc_check.sh $1 $2 $3
/usr/local/script下面存放腳本
Vim piddiff.sh
aapid為業務監控id 取值根據業務需求;
#/bin/sh
onl_ok=1
onl_cored=3
dir=/usr/local/script
if [[ ! -f "$dir/old.txt" ]];then
ps aux|grep aapid |grep -v grep|grep -v /bin/bash|awk '{print $2,$11}' > $dir/old.txt
else
sleep 1s
fi
ps aux|grep aapid |grep -v grep|grep -v /bin/bash|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
一個簡單的判斷腳本;
Zabbix30秒會抓取一次,正常沒變化為1,有變化為3,那麽zabbix抓取數值為3則表示pid有變化,會發出警報;
Zabbix設置:
監控項模板添加如下:
觸發器:{Template OS Linux:checkpid.last()}=3
zabbix監控業務進程變動