问题一,zabbix使ssh客户端监控top命令报“Value of type "string" is not suitable for value type "Numeric (float)". Value ""”
排查步骤:
1,最开始在“已执行的脚本”写“top -n 1 -b |grep "load"|cut -d "," -f 4|cut -d " " -f 5”,直接在主机上执行能获取到,
但通过ssh客户端就报上面的错误;
2,首先怀疑是返回值格式不正确,将“信息类型”修改为“浮点数”,写了个脚本:
#!/bin/bash
num=$(top -d 1 -n 1|grep "load"|cut -d "," -f 4|cut -d " " -f 5)
echo $num|bc
结果也是直接在主机上执行能获取到,但通过ssh客户端就报上面的错误;
3,后来创建了一个定时任务,在主机上定时执行:
脚本:
[root@node142 ~]# vi top-load.sh
#!/bin/bash
top -n 1 -b |grep "load"|cut -d "," -f 4|cut -d " " -f 5 > /root/top-load-result.txt
定时任务每分钟执行一次:
[root@node142 ~]# crontab -l
*/1 * * * * /root/top-load.sh > /dev/null
结果发现手动执行top-load.sh时top-load-result.txt有值,但定时执行后文件里就是空的了,说明确实是top命令执行后没有结果输出
4,将top命令的输出结果重定向到tmp下,发现结果文件里居然有内容了!!
top -n 1 -b |grep "load"|cut -d "," -f 4|cut -d " " -f 5 > /tmp/top-load-result.txt
5,直接在zabbix的“已执行脚本”里写脚本:
#!/bin/bash
top -n 1 -b |grep "load"|cut -d "," -f 4|cut -d " " -f 5 > /tmp/top-load-result.txt
cat /tmp/top-load-result.txt |sed -n "1p"
这样也可以获取到想监控的负载值了