monitoring-zabbix/netstat/netstat_conn.sh

40 lines
832 B
Bash
Executable File

#!/bin/bash
#Netstat connections monitoring
METRIC="$1"
if [[ -z "$1" ]]; then
echo "Please enter metric"
exit 1
fi
CACHETTL="55" # Время действия кеша в секундах (чуть меньше чем период опроса элементов)
CACHE="/tmp/netstat-status-`echo netstat| md5sum | cut -d" " -f1`.cache"
if [ -s "$CACHE" ]; then
TIMECACHE=`stat -c"%Z" "$CACHE"`
else
TIMECACHE=0
fi
TIMENOW=`date '+%s'`
if [ "$(($TIMENOW - $TIMECACHE))" -gt "$CACHETTL" ]; then
netstat -tan|grep -e ':80\|:443' > $CACHE || exit 1
fi
case $METRIC in
'established')
cat $CACHE | grep "ESTABLISHED" | wc -l
;;
'time_wait')
cat $CACHE | grep "TIME_WAIT" | wc -l
;;
*)
echo "Not selected metric"
exit 0
;;
esac