Linux:
The commands for manually obtaining TCP connections on Linux are:
netstat -an|awk '/^tcp/{++s[$NF]}end{for (A in S) print a,s[a]} ' #ESTABLISHED socket has established a connection #CLOSED socket not used, no connection #CLOSING both the server side and the client both close the connection #CLOSE_WAIT waiting to close the connection #TIME_WAIT said that it received the fin message and sent an ACK message, waiting for 2MSL to return to closed status #LAST_ACK remote shutdown, current socket passive shutdown after sending fin message, waiting for each other ACK message #LISTEN monitoring status #SYN_RECV receive SYN messages #SYN_SENT has sent a SYN message
To edit a configuration file on the zabbix_agent side:
vi/etc/zabbix/zabbix_agentd.confinclude=/etc/zabbix/zabbix_agentd.d/
#编写一个获取tcp状态的脚本:mkdir /etc/zabbix/zabbix_agentd.d/script #此处注意, you must not put the script directly to/etc/zabbix/ zabbix_agentd.d/directory, otherwise zabbix_agent will take it as its own configuration file execution, causing the restart is unsuccessful Vi /etc/zabbix/zabbix_agentd.d/script/tcp_ Status.sh#!/bin/bash#this script is get tcp statusmetric=$1tmp_file=/tmp/tcp_ status.txt/bin/netstat -an|awk '/^tcp/{++s[$NF]}end{for (a in s) print a,S[a]} ' > $tmp _file case $metric in closed) output=$ (awk '/closed/{print $2} ' $tmp _file) if [ "$output" == " ];then echo 0 else echo $output fi ;; listen) output=$ (awk '/ listen/{print $2} ' $tmp _file) if [ "$output" == " ];then echo 0 else echo $output fi ;;    SYNRECV) output=$ (awk '/SYN_ recv/{print $2} ' $tmp _file) if [ "$output" == " ];THEN     &Nbsp; echo 0 else echo $ output fi ;; synsent) output=$ (awk '/SYN_ sent/{print $2} ' $tmp _file) if [ "$output" == " ];then echo 0 else echo $output fi ;; established) output=$ (awk '/established/{print $2} ' $tmp _file) if [ "$output" == " ];then echo 0 else echo $output fi ;; timewait) output=$ (awk '/ time_wait/{print $2} ' $tmp _file) if [ "$output" == "" ];then echo 0 else echo $output fi ;; closing) output=$ (awk '/ closing/{print $2} ' $tmp _file) if [ "$output" == " ];then echo 0 else echo $output fi ;; closewait) output=$ (awk '/ close_wait/{print $2} ' $tmp _file) if [ "$output" == "" ];then echo 0 else echo $ output fi ;; lastack) output=$ (awk '/LAST _ack/{print $2} ' $tmp _file) if [ "$output" == " ];then echo 0 else echo $output fi ;;    FINWAIT1) output=$ (awk '/FIN _wait1/{print $2} ' $tmp _file) if [ "$output" == " ];then echo 0 else echo $output fi ;;    FINWAIT2) output=$ (awk '/FIN _wait2/{print $2} ' $tmp _file) if [ "$output" == " ];then echo 0 else echo $output fi ;; *) echo -e "\e[033musage: sh $0 [closed|closing|closewait|synrecv|synsent| finwait1|finwait2|listen|established|lastack|timewait]\e[0m " esac
#赋予脚本可执行权限chmod +x/
To write a custom key on zabbix_agent:
Vi/etc/zabbix/zabbix_agentd.confuserparameter=tcp.status[*],/etc/zabbix/zabbix_agentd.d/script/tcp_status.sh $
Restart Zabbix_agent:
/etc/init.d/zabbix_agent restart
The value returned by the test input parameter on the server side:
Zabbix_get-s 118.190.114.140-p 10050-k Tcp.status[listen]
Finally on the Zabbix to create monitoring items and triggers, attachments upload an attachment, which is the tcp_status template, directly in the configuration-template-Import.
Windows:
The command to manually obtain the number of TCP connections on Windows is:
This article from "Wang Jiadong elder brother" blog, declined reprint!
Zabbix monitoring the number of TCP connections for Linux and Windows