-
Notifications
You must be signed in to change notification settings - Fork 31
/
any_connections.sh
executable file
·40 lines (34 loc) · 1.29 KB
/
any_connections.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
# Cloudkick plugin to count number of connections.
# Alerts if no clients and/or no listeners.
# ----------------------------------------------------------------------------
# "THE BEER-WARE LICENSE" (Revision 42):
# <[email protected]> wrote this file. As long as you retain this notice you
# can do whatever you want with this stuff. If we meet some day, and you think
# this stuff is worth it, you can buy me a beer in return
# ----------------------------------------------------------------------------
if [ $# -ne 1 ]; then
echo -e "usage `basename $0` <port to check>\nwhere <port to check> is 443 for https, 3306 for mysql, etc.\nalerts if no clients and/or listeners"
exit 1
fi
PORT=$1
NOW=`netstat -an|grep -v 'LISTEN'`
SIMULTANEOUS=`echo $NOW|grep -c :$PORT\ `
ACTIVE=`echo "$NOW" |grep -c ESTABLISHED`
IDLE=`echo "$NOW" |grep -c TIME_WAIT`
CLOSING=`echo "$NOW" |grep -c FIN`
if [ $SIMULTANEOUS -lt 1 ]; then
if [ $SIMULTANEOUS -lt 0 ]; then
echo "status err no server listening!"
SIMULTANEOUS=0
else
echo "status err no users connected!";
fi
exit
else
echo "status ok ok";
fi
echo "metric port$PORT\users int $SIMULTANEOUS";
echo "metric port$PORT\users_active int $ACTIVE";
echo "metric port$PORT\users_idle int $IDLE";
echo "metric port$PORT\users_closing int $CLOSING";