zabbix4.0版本(三)
1. 自定义监控项TCP状态
1.实现
[root@zabbix-agent zabbix]# netstat -antp|awk 'NR>2{print $6}'|grep "TIME_WAIT"|wc -l
2.自定义监控 =自定义监控项的键名称,取值的命令
UserParameter=mysql.ping,HOME=/var/lib/zabbix mysqladmin ping | grep -c alive
3.zabbix客户端获取值
[root@zabbix-agent zabbix_agentd.d]# netstat -antp|awk 'NR>2{print $6}'|grep "TIME_WAIT"|wc -l
4.创建文件tcp_status.conf
[root@zabbix-agent zabbix_agentd.d]# pwd
/etc/zabbix/zabbix_agentd.d
[root@zabbix-agent 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
调用Include=/etc/zabbix/zabbix_agentd.d/*.conf下的tcp_status.conf获取值.
5.客户端重启
[root@zabbix-agent zabbix_agentd.d]# systemctl restart zabbix-agent
6.服务端获取值
[root@zabbix-server ~]# zabbix_get -s 122.112.164.83 -k TIME_WAIT
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.) 看下zabbix以什么用户运行的,把获取值的netstat -latp去掉p
19
[root@zabbix-server ~]# zabbix_get -s 122.112.164.83 -k TIME_WAIT
23
7. 找到被监控的主机创建监控项
创建TIME_WAIT完成之后其他的两个监控项直接克隆即可