Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add check for haproxy queue depth

  • Loading branch information...
commit f7d6d348ed87e4d7d9f28177a3747577efdfeeeb 1 parent a8abda3
@sax sax authored
Showing with 90 additions and 0 deletions.
  1. +90 −0 check_haproxy_queue
View
90 check_haproxy_queue
@@ -0,0 +1,90 @@
+#!/bin/bash
+# ========================================================================================
+# HAProxy nagios check of current queue depth.
+#
+# 2013 Wanelo Inc, Apache License.
+#
+# Usage: ./check_haproxy_queue [-s stats_socket] [-b backend ]
+# [-w <warn_cnt>] [-c <critical_cnt>]
+# -b --backend name of backend to watch (ie "app_servers")
+# -s --stats_socket location of haproxy stats socket (default /var/run/haproxy.sock)
+# -w --warning warning threshold (default 100)
+# -c --critical critical threshold (default 500)
+# ========================================================================================
+
+# Nagios return codes
+STATE_OK=0
+STATE_WARNING=1
+STATE_CRITICAL=2
+STATE_UNKNOWN=3
+
+QUEUE=0
+NODENAME=`cat /etc/nodename`
+STATS_SOCKET=/var/run/haproxy.sock
+
+# set thresholds in bytes
+WARNING_THRESHOLD=100
+CRITICAL_THRESHOLD=500
+
+# Parse parameters
+while [ $# -gt 0 ]; do
+ case "$1" in
+ -b | --backend)
+ shift
+ BACKEND=$1
+ ;;
+ -s | --stats_socket)
+ shift
+ STATS_SOCKET=$1
+ ;;
+ -w | --warning)
+ shift
+ WARNING_THRESHOLD=$1
+ ;;
+ -c | --critical)
+ shift
+ CRITICAL_THRESHOLD=$1
+ ;;
+ *) echo "Unknown argument: $1"
+ exit $STATE_UNKNOWN
+ ;;
+ esac
+shift
+done
+
+function result {
+ DESCRIPTION=$1
+ STATUS=$2
+
+ if [ -z "$MESSAGE" ]; then
+ MESSAGE="current queue size is $QUEUE"
+ fi
+
+ echo "QUEUE $DESCRIPTION : ${NODENAME} $MESSAGE|queue=${QUEUE};${WARNING_THRESHOLD};${CRITICAL_THRESHOLD}"
+ exit $STATUS
+}
+
+function exit_on_error {
+ if [ $1 -ne 0 ]; then
+ MESSAGE=$2
+ result "CRITICAL" $STATE_CRITICAL
+ fi
+}
+
+if [ -z "$BACKEND" ]; then
+ MESSAGE="missing backend parameter"
+ result "CRITICAL" $STATE_CRITICAL
+fi
+
+STATS=`echo "show stat -1 2 -1" | nc -U $STATS_SOCKET | grep $BACKEND`
+exit_on_error $? "error checking stats socket"
+QUEUE=`echo $STATS | cut -d',' -f3`
+
+# Output response
+if [ $QUEUE -ge $WARNING_THRESHOLD ] && [ $QUEUE -lt $CRITICAL_THRESHOLD ]; then
+ result "WARNING" $STATE_WARNING
+elif [ $QUEUE -ge $CRITICAL_THRESHOLD ]; then
+ result "CRITICAL" $STATE_CRITICAL
+else
+ result "OK" $STATE_OK
+fi
Please sign in to comment.
Something went wrong with that request. Please try again.