본문 바로가기
Zabbix

[zabbix] TCP 모니터링 하는 법

by freesunny 2019. 11. 26.

zabbix 3.4 이상에서 사용할수 있는 방법이다.

zabbix: tcp 그래프

 

/usr/local/bin/json_item_tcp.sh

#!/bin/bash
# for Linux
 
STATS=(UNKNOWN:0 ESTABLISHED:0 SYN_SENT:0 SYN_RECV:0 FIN_WAIT1:0 FIN_WAIT2:0 TIME_WAIT:0 CLOSED:0 CLOSE_WAIT:0 LAST_ACK:0 LISTEN:0 CLOSING:0)
CONN="$(awk '{print $4}' /proc/net/tcp /proc/net/tcp6 | grep -v st | sort | uniq -c | sed -e s/' 0'/' '/g -e s/'A'/'10'/g -e s/'B'/'11'/g | awk '{print $2":"$1}')"
 
if [ ! -z "$CONN" ];then
    for s in $CONN
    do
        STATS[${s%%:*}]=${STATS[${s%%:*}]%%:*}":"${s#*:}
    done
fi
echo ${STATS[@]} | sed -e s/' '/',"'/g -e s/':'/'":'/g -e s/^/'{"tcp_conn":{"'/g -e s/'WAIT_'/'WAIT'/g -e s/'$'/'}}'/g
 

 

 

실행 권한 부여

chmod +x /usr/local/bin/json_item_tcp.sh

 

 

/etc/zabbix/zabbix_agentd.d/userparameter_tcp.conf

 

 

zabbix-agent 재시작 

systemctl restart zabbix-agent.service

 

import template

https://github.com/tanrakukairo/zabbix_template_tcp_connections/blob/master/3.4_tcp_templates.xml

 

 

참고사이트 : https://github.com/tanrakukairo/zabbix_template_tcp_connections