Zabbix Agent 安装3

2022-03-22 11:50:09 浏览数 (1)

配置监控插件

代码语言: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]#

配置完监控插件后,要重启agent

Note: 如果不重启,就读不到新添的配置,从服务端尝试获取信息,会出现如下报错

代码语言:javascript复制
[root@zbx-server zabbix_agentd.d]#  zabbix_get -s zbx-target -p 10050 -k "mem.used"
ZBX_NOTSUPPORTED: Unsupported item key.
[root@zbx-server zabbix_agentd.d]#  zabbix_get -s zbx-target -p 10050 -k "port.discovery"
ZBX_NOTSUPPORTED: Unsupported item key.
[root@zbx-server zabbix_agentd.d]# 

重启agent

代码语言:javascript复制
[root@zbx-target zabbix_agentd.d]# /etc/init.d/zabbix-agent restart 
Shutting down Zabbix agent:                                [  OK  ]
Starting Zabbix agent:                                     [  OK  ]
[root@zbx-target zabbix_agentd.d]# 

然后再尝试从服务端进行信息采集

代码语言:javascript复制
[root@zbx-server zabbix_agentd.d]#  zabbix_get -s zbx-target -p 10050 -k "port.discovery"
{"data":[{"{#OPENPORT}":"57091"},{"{#OPENPORT}":"55581"},{"{#OPENPORT}":"10050"},{"{#OPENPORT}":"10010"},{"{#OPENPORT}":"631"},{"{#OPENPORT}":"111"},{"{#OPENPORT}":"25"},{"{#OPENPORT}":"22"},{"{#OPENPORT}":"END"}]}
[root@zbx-server zabbix_agentd.d]#  zabbix_get -s zbx-target -p 10050 -k "mem.used"
623308
[root@zbx-server zabbix_agentd.d]# 

一切正常

到此,基础工作已经完成,在此前提下,配置 Templates,创建 Graphs ,拼接 Screens 就可以展示出非常炫目的dashboard效果


命令汇总

  • wget http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpm
  • zabbix_get -s zbx-target -p 10050 -k "system.cpu.load[all,avg1]"
  • zabbix_get -s zbx-target -p 10050 -k "system.cpu.load[all,avg5]"
  • zabbix_get -s zbx-target -p 10050 -k "system.cpu.load[all,avg15]"
  • zabbix_get -s zbx-target -p 10050 -k "net.tcp.listen[10050]"
  • zabbix_get -s zbx-target -p 10050 -k "net.tcp.listen[10051]"
  • zabbix_get -s zbx-target -p 10050 -k "system.boottime"
  • zabbix_get -s zbx-target -p 10050 -k "agent.version"
  • zabbix_get -s zbx-target -p 10050 -k "net.if.discovery"
  • zabbix_get -s zbx-target -p 10050 -k "system.cpu.discovery"
  • zabbix_get -s zbx-target -p 10050 -k "system.sw.arch"
  • cat port.discovery.bash
  • cat userparameter_DIY.conf
  • zabbix_get -s zbx-target -p 10050 -k "port.discovery"
  • zabbix_get -s zbx-target -p 10050 -k "mem.used"

原文地址

0 人点赞