赞
踩
[root@localhost ~]# cd /etc/zabbix/
[root@localhost zabbix]# mkdir scripts
[root@localhost scripts]# pwd
/etc/zabbix/scripts
[root@localhost scripts]# cat system.sh
#!/bin/bash
mem_use=$( free -m|grep Mem|awk '{printf "%.2f\n",$3/$2*100}')
cpu_free=$( top -bn1 |sed -n 3p|awk '{printf "%d\n", $8}')
cpu_use=$( top -bn1 |sed -n 3p|awk '{printf "%d\n", 100-$8}')
case $1 in
mem_use)
echo $mem_use ;;
cpu_free)
echo $cpu_free ;;
cpu_use)
echo $cpu_use ;;
*)
echo "输入有误!!!"
esac
注意!!!使用 top 命令时不加 -b 参数会报以下错误
'unknown': unknown terminal type.
chmod +x system.sh
vim /etc/zabbix/zabbix_agentd.conf
开启用户自定义脚本
287 UnsafeUserParameters=1
定义用户自定义脚本,并指明脚本的存放路径
296 UserParameter=check_mem[*],/etc/zabbix/scripts/system.sh
systemctl restart zabbix-agent
返回数据成功
[root@localhost ~]# zabbix_get -s 192.168.153.185 -k check.system[cpu_use]
2
[root@localhost ~]# zabbix_get -s 192.168.153.185 -k check.system[cpu_free]
98
[root@localhost ~]# zabbix_get -s 192.168.153.185 -k check.system[mem_use]
13.30
[root@localhost ~]#
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。