zabbixはどのようにtcp接続数を監視しますか?
3033 ワード
参照http://john88wang.blog.51cto.com/2165294/1586234/
tcpの各状態の意味:
ESTABLISHED socketはすでに接続を確立しました。
CLOED socketは使われていません。接続はありません。
CLOSPING サーバ側とクライアントは同時に接続をオフにします。
CLOSE_WAIT 接続を閉じるのを待つ
TIME_WAIT The socket is waiting after close to handle packets still in the network.相手のFINの報文を受け取ったことを表して、そしてACKの報文を発送して、2 M SLを待ってからCLOEDの状態に戻ることができます。
ラスト.ACK The remote end has shut down,and the socket is closed.Waiting for acknowledgement.遠端は閉鎖して、現在socketは受動的に閉鎖した後にFIN報文を送ります。相手のACKの報文を待ちます。
LISTER 待ち受け状態
SYN_RECV SYNメッセージを受信しました
SYN_SENT SYNメッセージを送りました。
FIN_WAIT 1 The socket is closed、and the connection is shutting down
FIN_WAIT 2 Connection is closed,and the socket is waiting for a shutdown from the remote end.
1構築環境:
zabbox server:centos 6 ip 192.168.234.134
zabbbix client(nginx):centos 7 ip:192.168.234.133
2モニタ方法:
第一の監視方法はssを使います。
vi /usr/local/zabbix/scripts/tcp.sh
5リンクをテストします
ザブックスget-s 192.168.234.133-p 10055-k tcp.status[timewait]
6テンプレートに流し込み、図を確認する
tcpの各状態の意味:
ESTABLISHED socketはすでに接続を確立しました。
CLOED socketは使われていません。接続はありません。
CLOSPING サーバ側とクライアントは同時に接続をオフにします。
CLOSE_WAIT 接続を閉じるのを待つ
TIME_WAIT The socket is waiting after close to handle packets still in the network.相手のFINの報文を受け取ったことを表して、そしてACKの報文を発送して、2 M SLを待ってからCLOEDの状態に戻ることができます。
ラスト.ACK The remote end has shut down,and the socket is closed.Waiting for acknowledgement.遠端は閉鎖して、現在socketは受動的に閉鎖した後にFIN報文を送ります。相手のACKの報文を待ちます。
LISTER 待ち受け状態
SYN_RECV SYNメッセージを受信しました
SYN_SENT SYNメッセージを送りました。
FIN_WAIT 1 The socket is closed、and the connection is shutting down
FIN_WAIT 2 Connection is closed,and the socket is waiting for a shutdown from the remote end.
1構築環境:
zabbox server:centos 6 ip 192.168.234.134
zabbbix client(nginx):centos 7 ip:192.168.234.133
2モニタ方法:
第一の監視方法はssを使います。
/usr/sbin/ss state all | awk '{++S[$1]} END {for (a in S) {printf "%11-s %s
",a,S[a]}}'
LISTEN 9
ESTAB 1
State 1
TIME-WAIT 110
第二のモニタ方法はnetstatを使用します。/bin/netstat -an|awk '/^tcp/{++S[$NF]}END{for(a in S) print a,S[a]}'
LISTEN 9
ESTABLISHED 1
SYN_SENT 1
TIME_WAIT 126
3 モニタスクリプト作成vi /usr/local/zabbix/scripts/tcp.sh
#!/bin/bash
#this script is used to get tcp and udp connetion status
#tcp status
metric=$1
tmp_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
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)
4 zabbbixクライアントプロファイルを追加します。vi /usr/local/zabbix/etc/zabbix_agentd.conf
UserParameter=tcp.status[*],/usr/local/zabbix/scripts/tcp.sh $1
そして、agentdサービスを再開します。5リンクをテストします
ザブックスget-s 192.168.234.133-p 10055-k tcp.status[timewait]
6テンプレートに流し込み、図を確認する