这个脚本是用来进行端口发现的,作为基础服务提供给其它监控条目使用
代码语言:javascript复制Note: zabbix用户要有这个脚本的执行权限,因为实际信息收集过程中,是以zabbix这个用户的身份进行的
[root@zbx-target zabbix_agentd.d]# ps faux | grep zabbix | grep -v "grep"
zabbix 26928 0.0 0.0 77336 1136 ? S 17:02 0:00 zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf
zabbix 26930 0.0 0.0 77388 2028 ? S 17:02 0:00 _ zabbix_agentd: collector [idle 1 sec]
zabbix 26931 0.0 0.0 77388 1372 ? S 17:02 0:00 _ zabbix_agentd: listener #1 [waiting for connection]
zabbix 26932 0.0 0.0 77388 1368 ? S 17:02 0:00 _ zabbix_agentd: listener #2 [waiting for connection]
zabbix 26933 0.0 0.0 77388 1412 ? S 17:02 0:00 _ zabbix_agentd: listener #3 [waiting for connection]
zabbix 26934 0.0 0.0 77344 1128 ? S 17:02 0:00 _ zabbix_agentd: active checks #1 [idle 1 sec]
[root@zbx-target zabbix_agentd.d]#
配置监控插件
代码语言:javascript复制[root@zbx-target zabbix_agentd.d]# vim userparameter_DIY.conf
[root@zbx-target zabbix_agentd.d]# cat userparameter_DIY.conf
#UserParameter=swap.in.ps,/usr/bin/sar -W 1 1 | grep Average | awk {'print $2'}
#UserParameter=swap.out.ps,/usr/bin/sar -W 1 1 | grep Average | awk {'print $3'}
UserParameter=mem.used,/usr/bin/free -k | grep | awk '{print $3}'
UserParameter=ps.proc.sum[*],/bin/ps faux | grep "$1" | grep -v 'grep' | awk 'BEGIN{sum=0;}{sum=sum $$$2;}END{print sum*1024;}'
UserParameter=ps.proc[*],/bin/ps faux | grep "$1" | grep -v 'grep' | awk '{print $$$2*1024}' | head -n 1
UserParameter=ps.proc.psum[*],/bin/ps faux | grep "$1" | grep -v 'grep' | awk 'BEGIN{sum=0;}{sum=sum $$$2;}END{print sum;}'
UserParameter=ps.proc.p[*],/bin/ps faux | grep "$1" | grep -v 'grep' | awk '{print $$$2}' | head -n 1
UserParameter=redis.stat[*],/usr/local/bin/redis-cli -h 127.0.0.1 -p $1 info $2 | grep $3: | cut -f 2 -d ':'
UserParameter=port.discovery,/etc/zabbix/zabbix_agentd.d/script/port.discovery.bash
UserParameter=kernal.sysctl[*], (/sbin/sysctl -n $1 2> /dev/null || /sbin/sysctl -n $2 2> /dev/null ) | /bin/awk '{print $$$3}'
UserParameter=mongo.slowlog[*], /usr/bin/tail -n $1 $2 | awk 'BEGIN{sum=0;}{sum= sum ($NF-0)}END{print sum/$1}'
UserParameter=mysql.slowlog[*], /usr/bin/tail -n $1 $2 | grep Query_time | awk 'BEGIN{sum=0;}{sum= sum ($$3-0)}END{print sum/NR}'
[root@zbx-target zabbix_agentd.d]#