zabbix监控之进程自动发现
Posted Tank
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zabbix监控之进程自动发现相关的知识,希望对你有一定的参考价值。
1,获取要监控的进程到/tmp/process_list.txt文件
cat process_list.sh
#!/bin/bash
cat /dev/null >/tmp/process_list.txt if [ `ps aux|grep "/data/apache_projects/tomcat7-express-18034"|grep -v grep |wc -l` -gt 0 ];then echo "/data/apache_projects/tomcat7-express-18034" >>/tmp/process_list.txt;fi if [ `ps aux|grep "/usr/local/webserver/tengine/sbin/nginx"|grep -v grep |wc -l` -gt 0 ];then echo "/usr/local/webserver/tengine/sbin/nginx" >>/tmp/process_list.txt;fi
if [ `ps aux|grep "/usr/local/mysql/bin/mysqld"|grep -v grep |wc -l` -gt 0 ];then echo "/usr/local/mysql/bin/mysqld" >>/tmp/process_list.txt;fi
2,配置自动发现脚本
cat process_discovery.sh
#!/bin/bash COUNT=`cat /tmp/process_list.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,配置数据脚本
cat process_monitor.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/process_list.sh 2>/dev/null
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/process_monitor.sh $1 $2
以上是关于zabbix监控之进程自动发现的主要内容,如果未能解决你的问题,请参考以下文章