zabbix监控之进程自动发现
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zabbix监控之进程自动发现相关的知识,希望对你有一定的参考价值。
1,配置要监控的进程标识
vim processlist.sh
cat /dev/null >/tmp/processlist.txt
if [ `ps aux|grep "apache-tomcat-7.0.56-59002/temp"|grep -v grep |wc -l` -gt 0 ];then echo "apache-tomcat-7.0.56-59002/temp" >>/tmp/processlist.txt;fi
if [ `ps aux|grep "zoo.cfg"|grep -v grep |wc -l` -gt 0 ];then echo "zoo.cfg" >>/tmp/processlist.txt;fi
2,配置自动发现脚本
vim pro_dis.sh
#!/bin/bash
COUNT=`cat /tmp/pro.txt|wc -l`
INDEX=0
echo ‘{"data":[‘
cat /tmp/pro.txt | while read LINE; do
echo -n ‘{"{#TABLENAME}":"‘$LINE‘"}‘
INDEX=`expr $INDEX + 1`
if [ $INDEX -lt $COUNT ]; then
echo ‘,‘
fi
done
echo ‘]}‘
3,配置数据脚本
vim process.sh
#!/bin/bash
process=$1
name=$2
case $2 in
cpu)
cat /tmp/ps.txt |grep $process |awk ‘{print $3}‘
;;
mem)
cat /tmp/ps.txt |grep $process |awk ‘{print $4}‘
;;
rss)
cat /tmp/ps.txt |grep $process |awk ‘{print $6}‘
;;
count)
cat /tmp/ps.txt |grep $process |wc -l
;;
*)
echo "Error input:"
;;
esac
exit 0
4,添加到crontab
*/1 * * * * ps aux > /tmp/ps.txt 2>/dev/null
* 23 * * * sh /etc/zabbix/scripts/processlist.sh 2>/dev/null
自动添加crontab
cat cron.sh
#!/bin/sh
PROGRAM="ps aux"
CRONTAB_CMD="*/1 * * * * $PROGRAM > /tmp/ps.txt 2>/dev/null"
(crontab -l 2>/dev/null | grep -Fv "$PROGRAM"; echo "$CRONTAB_CMD") | crontab -
COUNT=`crontab -l | grep "$PROGRAM" |wc -l`
if [ $COUNT -lt 1 ]; then
echo "fail to add crontab $PROGRAM"
exit 1
fi
5,配置process_discovery.conf文件
cat /etc/zabbix/zabbix_agentd.d/process_discovery.conf
#ps process
UserParameter=process.discovery,/etc/zabbix/scripts/process_discovery.sh
UserParameter=process[*],/etc/zabbix/scripts/processmonitor.sh \$1 \$2
以上是关于zabbix监控之进程自动发现的主要内容,如果未能解决你的问题,请参考以下文章