zabbix监控tcp的11种状态
监控tcp的11种状态
- 通过shell脚本,传递参数,根据参数返回结果
[root@zabbix_agent zabbix]# pwd /etc/zabbix [root@zabbix_agent zabbix]# mkdir shell && cd shell [root@zabbix_agent shell]# vim tcp_status.sh #!/bin/bash metric=$1 tmp_file=/tmp/tcp_status.txt /usr/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 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
[root@zabbix_agent tmp]# systemctl restart zabbix-agent #重启zabbix-agent - 在server端通过zabbix_get工具测试
[root@zabbix_server ~]# zabbix_get -s 192.168.1.130 -k tcp.status[] Usage: sh /etc/zabbix/shell/tcp_status.sh [closed|closing|closewait|synrecv|synsent|finwait1|finwait2|listen|established|lastack|timewait] [root@zabbix_server ~]# zabbix_get -s 192.168.1.130 -k tcp.status[timewait] 26
- 导入模板
模板地址https://gitee.com/appdevel/dev.git


- 链接模板




浙公网安备 33010602011771号