zabbix使ssh客户端监控top命令报“Value of type “string“ is not suitable for value type “Numeric (float)“. Value

问题一,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"

这样也可以获取到想监控的负载值了

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值