Add scripts to view sip and memcache connections and stats
authorAndy Witter <awitter@georgialibraries.org>
Fri, 13 Jan 2017 22:54:48 +0000 (17:54 -0500)
committerAndy Witter <awitter@georgialibraries.org>
Fri, 13 Jan 2017 22:54:48 +0000 (17:54 -0500)
GenaSYS.sh
templates/SIP/sip_stats [new file with mode: 0755]
templates/memcache/check_memcache_connections.sh [new file with mode: 0755]

index b433b50..224979d 100755 (executable)
@@ -25,7 +25,7 @@
     PURPOSE_="Generate config files needed for Evergreen-ILS Cluster"
    SYNOPSIS_="$NAME_"
    REQUIRES_="standard GNU commands, apt, dpkg"
-    VERSION_="1.74"
+    VERSION_="1.75"
        DATE_="2010-11-23; last update: 2017-01-13"
      AUTHOR_="Andy Witter <awitter@georgialibraries.org>"
         URL_="http://evergreen-ils.org"
@@ -2514,6 +2514,13 @@ done
 }
 SetupInterfaces
 
+### Setup Memcache
+for MEMCACHE_NODE in $MACHINES_MEMCACHE_ONLY
+do
+       mkdir -p "$OUTDIR/$MEMCACHE_NODE/usr/local/bin"
+       cp -f "$TEMPLATEDIR/memcache/check_memcache_connections.sh" "$OUTDIR/$MEMCACHE_NODE/usr/local/bin"
+done
+
 ### Setup Utility
 ### setup exports for utility.
 
@@ -2621,10 +2628,12 @@ do
        mkdir -p "$OUTDIR/$SIPNODE/etc/cron.d"
        mkdir -p "$OUTDIR/$SIPNODE/var/www"
        mkdir -p "$OUTDIR/$SIPNODE/root/eg"
+       mkdir -p "$OUTDIR/$SIPNODE/usr/local/bin"
        tar zxf $TEMPLATEDIR/SIP/SIPServer.tar.gz -C "$OUTDIR/$SIPNODE/opt"
        cp -f $TEMPLATEDIR/SIP/sip.init "$OUTDIR/$SIPNODE/etc/init.d/oils_sip"
        cp -f $TEMPLATEDIR/SIP/eg_sip_root.crontab "$OUTDIR/$SIPNODE/root/eg"
        cp -f $TEMPLATEDIR/SIP/display_sip_connections.sh "$OUTDIR/$SIPNODE/root/eg"
+       cp -f $TEMPLATEDIR/SIP/sip_stats "$OUTDIR/$SIPNODE/usr/local/bin"
 done
 echo "Done setting up SIP."
 
diff --git a/templates/SIP/sip_stats b/templates/SIP/sip_stats
new file mode 100755 (executable)
index 0000000..4c22726
--- /dev/null
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+### Display some statistics on the SIP Server.
+
+CONNECTED_HOSTS=$(netstat -lan | grep 6001 | grep ESTAB | awk '{ print $5 }' | awk -F":" '{ print $1 }' |sort | uniq -c | sort -nr)
+PROCESSES=$(ps -ef | grep -v color )
+
+echo
+echo "$HOSTNAME"
+echo "___SIP Connected Hosts___"
+echo "$CONNECTED_HOSTS"
+echo -n Total:" ";echo "$CONNECTED_HOSTS" | wc -l
+echo
+echo "___Drone Count___"
+echo "$PROCESSES" | grep Drone | wc -l
+echo
+echo "__SIP Server Processes__"
+echo "$PROCESSES" | grep SIPServer | wc -l
diff --git a/templates/memcache/check_memcache_connections.sh b/templates/memcache/check_memcache_connections.sh
new file mode 100755 (executable)
index 0000000..b0a2faf
--- /dev/null
@@ -0,0 +1,47 @@
+#!/bin/bash
+
+### Get the IP of hosts connected to memcache port 11211 with TCP state ESTABLISHED.
+ALL_CONNECTIONS="$(netstat -lan|grep 11211|grep "ESTABLISHED" | grep -v "tcp6\|udp" | awk '{ print $5 }'| awk -F":" '{ print $1 }'|sort -n)"
+TOTAL_CONNECTIONS="$(echo "$ALL_CONNECTIONS" | wc -l)"
+CONNECTED_HOSTS=$(echo "$ALL_CONNECTIONS" | uniq)
+#echo $CONNECTED_HOSTS
+#echo "$CONNECTED_HOSTS"
+#echo "$ALL_CONNECTIONS"
+#exit
+
+Check_Connections () { ### Display the number of connections per host
+echo
+echo "Hostname: $HOSTNAME"
+echo "Established Remote connections to Memcache."
+echo "==========================================="
+echo "Host IP    | No. of connections"
+echo "-------------------------------------------"
+for REMOTE_HOST in $(echo "$CONNECTED_HOSTS")
+do
+       echo -n $REMOTE_HOST " " ;echo "$ALL_CONNECTIONS" | grep "$REMOTE_HOST" | grep -v "tcp6\|udp"|wc -l
+done
+       echo "Total: $TOTAL_CONNECTIONS"
+}
+
+Watch_Connections () { ### Display connection in real time.
+watch -tn 0.5 'echo "###########################";echo Total memcached connections;netstat -lapn|grep 11211|grep "ESTABLISHED" | grep -v "tcp6\|udp"|wc -l'
+}
+
+Usage () { ### Display usage
+echo
+echo "Usage $0 [c|w|h]"
+}
+
+while getopts :cwh OPTIONS
+do      case "$OPTIONS" in
+        c)      Check_Connections;;
+        w)      Watch_Connections;;
+        h)      Usage ; exit 1;;
+       *)      Usage ;;
+        esac
+done
+
+if [ -z $1 ]
+then
+       Usage
+fi