1.取到TCP连接状态的值
[root@web01 ~]# netstat -antp | awk 'NR>2{print $6}' | grep "TIME_WAIT" | wc -l ##可以取到TIME_WAIT的个数,依次类推,可以设置多个监控项,监控不同TCP状态的值
63
2.编写配置文件
自定义监控 = 自定义监控项的键名称, 取值的命令
[root@web01 zabbix_agentd.d]# cat tcp_status.conf
UserParameter=TIME_WAIT,netstat -ant | awk 'NR>2{print $6}' | grep "TIME_WAIT" | wc -l
UserParameter=LISTEN,netstat -ant | awk 'NR>2{print $6}' | grep "LISTEN" | wc -l
UserParameter=ESTABLISHED,netstat -ant | awk 'NR>2{print $6}' | grep "ESTABLISHED" | wc -l
然后重启zabbix_agent
[root@web01 ~]# systemctl restart zabbix-agent.service
3.zabbix_sever命令行测试
[root@zabbix ~]# zabbix_get -s 172.16.210.53 -k TIME_WAIT
39
[root@zabbix ~]# zabbix_get -s 172.16.210.53 -k ESTABLISHED
1
[root@zabbix ~]# zabbix_get -s 172.16.210.53 -k LISTEN
9
每个状态都成功获取到了值
4.回到web界面添加监控项
配置
---主机
---选择对应的主机
---添加监控项
设置好对应的值和应用集,点击添加

再次点击创建好的监控项

点击克隆

只用更改对应的键值和名称,再点击
添加

添加好后,再点进监控项,点击克隆
,再创建一个监控项

查看设置好的三个监控项,确保启用

5.查看数据
监控
---最新数据
---选择需要查看的应用集

6.设置触发器
配置
---选择对应的主机
----触发器
添加表达式如图,TIME_WAIT
状态大于40报警

拉到底部,点击
添加
来添加触发器
如果当前TCP连接的
time_wait
状态大于40就会在主页看到这样的报错
回到主界面查看报警
一般出现问题,我们就要自己去解决,但由于这个TIME_WAIT我们现在无法解决,所以我们可以去把这个触发器的触发值调大

7.总结
zabbix的监控项可以自定义监控收集主机的信息,只要能取到值的东西就能监控,所以编写监控项也需要我们对linux的命令和基础系统知识有一定的了解
网友评论