# coding=utf-8 import sys import socket import re def check_server(address, port): s = socket.socket() print 'Attempting to connect to %s on port %s' % (address, port) try: s.connect((address, port)) print 'Connected to %s on port %s' % (address, por
监控原理 ss -ant | awk 'NR>1 {++s[$1]} END {for(k in s) print k,s[k]}' LAST-ACK 5ESTAB 348FIN-WAIT-1 11CLOSING 1FIN-WAIT-2 41TIME-WAIT 2447LISTEN 8 状态值的解释 ESTABLISHED: The socket has an established connection. SYN_SENT: The socket is actively attempting
#!/bin/bash #this script is used to get tcp and udp connetion status #tcp status metric=$ tmp_file=/tmp/tcp_status.txt /usr/sbin/ss -ant | awk '{++S[$1]};END {for(a in S) print a, S[a]}' > $tmp_file case $metric in closed) output=$(awk '/CLOSED/{prin