I wrote a simple plugin to check the number of established connections
to a windows server. Just execute:
cmd /c netstat -an |find /i “estab” /c
I also wrote a script for Windows
Here is the code
I have also done the same for a linux server. Just exec.:
netstat -an | grep -c EST
In fact that script is only 2 lines:
result=`netstat -anp | grep :81 | grep -c EST`
echo “Conexoes Totais = $result |Conexoes=$result”
Note that | will graph that result, witch is very usefull!
If we may need unique IP only then it should be something like:
netstat -an |grep ” 0 $port:8080″ |grep ESTA |awk ‘{print $5}’ |grep -v $port |cut -d “:” -f1 | sort -u |wc -l
Much Better:
ss -s |grep estab | awk ‘{print $4}’|tr -d “,”
There are many ways of getting that information, I have also
done the same thing via WMI, perfmon has that counter
and it maybe easier to for example find out the total number of
current connections to a specific website.
The script for windows is a .vbs and I call it using NC_NET
it can be downloaded here.
If you need just simple and fast use:
Here is the code:
#!/bin/bash
#Get number of current all estabilished connections
result=`ss -s |grep estab | awk '{print $4}'|tr -d ","`
echo "Conexoes Totais = $result |Conexoes=$result"
I just updated this old plugin, now it accepts argument and make graphs etc…
Example:
# ./check_con 1433 -w 1 -c 2 -f
OK – Connections on port 1433 = 0|Conections=0
#!/bin/bash
#Get current estabilished connections on Port
#Version 2.0
#By Felipe Ferreira August 2011
# Exit codes
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4
#Variables
port=8080
maxconwarn=10
maxconcrti=30
perfdata=0
#Check arguments print help
if [ $# -lt 1 ]; then
echo "Usage: $0 [-w|--warning ] [-c|--critical ] -f(for perdata)"
exit $STATE_UNKNOWN
fi
port=$1
#GET ARGUMENTS
while test -n "$1"; do
case "$1" in
--help)
echo "Uso: $0 [-w|--warning ] [-c|--critical ] -f(for perdata)"
exit $STATE_OK
;;
-h)
echo "Uso: $0 [-w|--warning ] [-c|--critical ] -f(for perdata)"
exit $STATE_OK
;;
--warning)
maxconwarn=$2
shift
;;
-w)
maxconwarn=$2
shift
;;
--critical)
maxconcrit=$2
shift
;;
-c)
maxconcrit=$2
shift
;;
-f)
perfdata=1
;;
-perfdata)
perfdata=1
;;
esac
shift
done
#EXECUTE THE COMMAND TO GET HOW MANY ESTABLISHED CONNECTIONS EXISTS
result=`netstat -an | grep ":$port" | grep -c ESTA`
#OR UNIQUE IP's ONLY, SET THE PORT HERE
#result=`netstat -anp |grep " 0 $port:8080" |grep ESTA |awk '{print $5}' |grep -v $port |cut -d ":" -f1 | sort -u |wc -l`
if [ $result -ge $maxconwarn ]; then
OUTPUT="WARNING - Connections on port $port = $result"
exitstatus=$STATE_WARNING
fi
if [ $result -ge $maxconcrit ]; then
OUTPUT="CRITICAL - Connections on port $port = $result"
exitstatus=$STATE_CRITICAL
fi
if [ $result -lt $maxconwarn ];then
OUTPUT="OK - Connections on port $port = $result"
exitstatus=$STATE_OK
fi
if [ $perfdata -eq 1 ]; then
OUTPUT="$OUTPUT|Conections=$result"
fi
echo $OUTPUT
exit $exitstatus

how to use this windows server script on nagios?