站点图标 IDC铺

zabbix 监控TCP状态连接数

1、zabbix客户端,监控TCP状态脚本,并保存到的定路径(/usr/local/zabbix-agent/shells)# cat zabbix_linux_plugin.sh#!/bin/bash。

############################################################# $Name:         zabbix_linux_plugins.sh# $Version:      v1.0

# $Function:     zabbix plugins# $Create Date:  2014-08-10# $Description:  Monitor Linux Service Status

############################################################tcp_status_fun(){TCP_STAT=$1ss -ant | awk NR>1 {++s[$1]} END {for(k in s) print k,s[k]} > /tmp/netstat.tmp

TCP_STAT_VALUE=$(grep “$TCP_STAT” /tmp/netstat.tmp | cut -d -f2)if [ -z $TCP_STAT_VALUE ];thenTCP_STAT_VALUE=0

fiecho $TCP_STAT_VALUE}main(){case $1 intcp_status)tcp_status_fun $2;;;*)echo $”Usage: $0 {tcp_status key}”

esac}main $1 $2 $32、在客户端中修改zabbix_agentd.conf配置文件(/usr/local/zabbix-agent/etc/zabbix_agentd.conf)### Option: Include

#       You may include individual files or all files in a directory in the configuration file.#       Installing Zabbix will create include directory in /usr/local/etc, unless modified during the compile time.

## Mandatory: no# Default:# Include=# Include=/usr/local/etc/zabbix_agentd.userparams.conf# Include=/usr/local/etc/zabbix_agentd.conf.d/

Include=/usr/local/zabbix-agent/etc/zabbix_agentd.conf.d/*.conf            # 启用Include,在zabbix_agentd.conf.d目录下的所有.conf文件被引用

用来引用自定义key的配置文件3、在客户端中配置自定义KEY配置文件(/usr/local/zabbix-agent/etc/zabbix_agentd.conf.d/zabbix-linux-plugin.conf)。

# cat zabbix-linux-plugin.conf UserParameter=linux_status[*],/usr/local/zabbix-agent/shells/zabbix_linux_plugin.sh “$1” “$2” “$3”

4、以上配置完成,重启zabbix agent服务# /etc/init.d/zabbix_agentd restart5、tcp连接状态模板,这是配置好的模板,包括了TCP连接的11种状态,如果模板就需要一个一个的创建了。

# cat TCP_export_templates.3.0.xml 3.0

2016-06-18T06:34:48ZTemplates

Template Linux TCP StatusTemplate Linux TCP Status

TemplatesTCP Stauts

TCP Status CLOSE_WAIT00

linux_status[tcp_status,CLOSE-WAIT]3003090

030

00

01

00

0

TCP StautsTCP Status CLOSED

00linux_status[tcp_status,CLOSED]

300309003

00

00

10

00

TCP Stauts

TCP Status CLOSING00

linux_status[tcp_status,CLOSING]3003090

030

00

01

00

0

TCP Stauts                           # ESTABLISHED状态模板,我们通过zabbix_get命令获取这个KEY,看是否可以正常获取

TCP Status ESTABLISHED00

linux_status[tcp_status,ESTAB]     # 这就是Key哦3003090

030

00

01

00

0

TCP StautsTCP Status FIN_WAIT1

00linux_status[tcp_status,FIN-WAIT-1]

300309003

00

00

10

00

TCP Stauts

TCP Status FIN_WAIT200

linux_status[tcp_status,FIN-WAIT-2]3003090

030

00

01

00

0

TCP StautsTCP Status LAST_ACK

00linux_status[tcp_status,LAST-ACK]

300309003

00

00

10

00

TCP Stauts

TCP Status LISTEN00

linux_status[tcp_status,LISTEN]30030900

30

00

01

00

0TCP Stauts

TCP Status SYN_RCVD0

0linux_status[tcp_status,SYN-RECV]300

309003

00

00

10

00

TCP Stauts

TCP Status SYN_SENT00

linux_status[tcp_status,SYN-SENT]3003090

030

00

01

00

0

TCP StautsTCP Status TIME_WAIT

00linux_status[tcp_status,TIME-WAIT]

300309003

00

00

10

00

TCP Stauts

TCP Status Statistics9002000.0000100.0000

1101

00.00000.00000

000

00C8000002

0Template Linux TCP Statuslinux_status[tcp_status,CLOSED]

1000C8000

20Template Linux TCP Statuslinux_status[tcp_status,CLOSE-WAIT]

200000C80

20Template Linux TCP Statuslinux_status[tcp_status,CLOSING]

30C800C80

20Template Linux TCP Statuslinux_status[tcp_status,ESTAB]

4000C8C80

20Template Linux TCP Statuslinux_status[tcp_status,FIN-WAIT-1]

50C8C8000

20Template Linux TCP Statuslinux_status[tcp_status,FIN-WAIT-2]

60C8C8C80

20Template Linux TCP Statuslinux_status[tcp_status,LAST-ACK]

709600000

20Template Linux TCP Statuslinux_status[tcp_status,LISTEN]

800096000

20Template Linux TCP Statuslinux_status[tcp_status,SYN-RECV]

900000960

20Template Linux TCP Statuslinux_status[tcp_status,SYN-SENT]

1009600960

20Template Linux TCP Statuslinux_status[tcp_status,TIME-WAIT]

6、zabbix server 端通过zabbix_get命令进行测试,验证是否可以正常获取TCP状态值

[root@linux-node1 ~]# zabbix_get -s 172.16.10.152 -k linux_status[tcp_status,ESTAB]   2[root@linux-node1 ~]# zabbix_get -s 172.16.10.152 -k linux_status[tcp_status,LISTEN]

6通过测试,我们可以看到,已经可以正确获取到值了,那么我们接下来,就可以在web页面将模板进行导入了。7、zabbix web 监控页面导入tcp连接状态模板

模板(TCP_export_templates.3.0.xml)导入成功后,将模板链接到一台就机就可以了。

最后我们来看下TCP状态有没有监控上吧。

好了,数据也有了,图形展示也有了,监控TCP状态就介绍到这里了。

退出移动版