Skip to content
Snippets Groups Projects
Commit 10d5d875 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

haproxy_status: add help on -h

parent a38fc56b
No related branches found
No related tags found
1 merge request!1296468-docs-and-harmonize
...@@ -16,43 +16,24 @@ ...@@ -16,43 +16,24 @@
# 2020-12-03 v1.4 <axel.hahn@iml.unibe.ch> added support of multiple front- and backends # 2020-12-03 v1.4 <axel.hahn@iml.unibe.ch> added support of multiple front- and backends
# 2021-12-14 v1.5 <axel.hahn@iml.unibe.ch> use updated haproxy paser in sourced file # 2021-12-14 v1.5 <axel.hahn@iml.unibe.ch> use updated haproxy paser in sourced file
# 2022-04-01 v1.6 <axel.hahn@iml.unibe.ch> use wget default params; shell fixes # 2022-04-01 v1.6 <axel.hahn@iml.unibe.ch> use wget default params; shell fixes
# 2022-10-21 v1.7 <axel.hahn@unibe.ch> remove grep: warning: stray \ before white space # 2022-10-21 v1.7 <axel.hahn@unibe.ch> remove grep: warning: stray \ before white space
# 2023-07-28 v1.8 <axel.hahn@unibe.ch> add help page
# ====================================================================== # ======================================================================
. $(dirname $0)/inc_pluginfunctions . $(dirname $0)/inc_pluginfunctions
. $(dirname $0)/inc_haproxy_cfg.sh
cfgfile=/etc/haproxy/haproxy.cfg export self_APPVERSION=1.8
. $(dirname $0)/inc_haproxy_cfg.sh
tmpfile=/tmp/check_haproxy_status_$$ tmpfile=/tmp/check_haproxy_status_$$
tmpfile2=/tmp/check_haproxy_status2_$$ tmpfile2=/tmp/check_haproxy_status2_$$
tmpfileping=/tmp/check_haproxy_status3_$$ tmpfileping=/tmp/check_haproxy_status3_$$
# ----------------------------------------------------------------------
# pre checks
# ----------------------------------------------------------------------
ph.require wget
if [ ! -f $cfgfile ]; then
ph.abort "UNKNOWN: config file does not exist: $cfgfile"
fi
cat $cfgfile >/dev/null
if [ $? -ne 0 ]; then
ph.abort "UNKNOWN: unable to read ha proxy config $cfgfile ... `ls -l $cfgfile`"
fi
cat $cfgfile | grep " mode .*http" >/dev/null
if [ $? -ne 0 ]; then
ph.abort "UNKNOWN: haproxy is not in http mode"
fi
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# functions # functions
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# find a column number of a given field name in haproxy csv # find a column number of a given field name in haproxy csv
function getColnumber(){ function getColnumber(){
cat $tmpfile | head -1 | sed 's#,#\n#g' | grep -n "^$1$" | cut -f 1 -d ':' cat $tmpfile | head -1 | sed 's#,#\n#g' | grep -n "^$1$" | cut -f 1 -d ':'
...@@ -60,9 +41,9 @@ function getColnumber(){ ...@@ -60,9 +41,9 @@ function getColnumber(){
# get stats data from column [name] # get stats data from column [name]
function getColumn(){ function getColumn(){
typeset -i local _iNumber=$1 typeset -i _iNumber=$1
local _filter=$2 local _filter=$2
test -z $_filter && _filter='.*' test -z "$_filter" && _filter='.*'
grep "$_filter" $tmpfile | grep -v "stats_frontend" | cut -f 2,$_iNumber -d ',' grep "$_filter" $tmpfile | grep -v "stats_frontend" | cut -f 2,$_iNumber -d ','
} }
...@@ -84,6 +65,72 @@ function checkStatus(){ ...@@ -84,6 +65,72 @@ function checkStatus(){
echo ERROR echo ERROR
fi fi
} }
# show help
function showHelp(){
local _self; _self=$(basename $0)
cat <<EOF
$( ph.showImlHelpHeader )
Check HA Proxy statistics on frontend and backend.
It shows if the status is OPEN or UP and show counts of current connectons.
The plugin reads $HAPROXYcfgfile to detect the required statistics url and get
csv data.
It requires wget to handle the http request.
Non OK values occur:
UNKNOWN - if $HAPROXYcfgfile cannot be read
- haproxy is not in http mode
- the url wasn't detected
- the detected status url doesn't send a response
ERROR - a frontend status is not OPEN
- a backend status is not UP
The plugin sends performance data.
SYNTAX:
$_self [-h]
OPTIONS:
-h or --help show this help.
EXAMPLE:
$_self
EOF
}
# ----------------------------------------------------------------------
# MAIN
# ----------------------------------------------------------------------
# --- check param -h
case "$1" in
"--help"|"-h")
showHelp
exit 0
;;
*)
esac
ph.require wget
if [ ! -f $HAPROXYcfgfile ]; then
ph.abort "UNKNOWN: config file does not exist: $HAPROXYcfgfile"
fi
if ! cat $HAPROXYcfgfile >/dev/null; then
ph.abort "UNKNOWN: unable to read ha proxy config $HAPROXYcfgfile ... $(ls -l $HAPROXYcfgfile)"
fi
if ! cat $HAPROXYcfgfile | grep " mode .*http" >/dev/null; then
ph.abort "UNKNOWN: haproxy is not in http mode"
fi
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# build url # build url
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
...@@ -102,7 +149,6 @@ urlmasked=$( echo $url | sed "s#\(://\)\(.*@\)#\1#g" ) ...@@ -102,7 +149,6 @@ urlmasked=$( echo $url | sed "s#\(://\)\(.*@\)#\1#g" )
# check output # check output
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# --- get status page # --- get status page
wget -T 5 -t 1 --no-check-certificate -O $tmpfile $url 2>/dev/null wget -T 5 -t 1 --no-check-certificate -O $tmpfile $url 2>/dev/null
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
...@@ -145,8 +191,6 @@ ph.status "FRONT: $statusFront - ${iFrontend} (max: ${iMaxConnFront}) .. BACK: $ ...@@ -145,8 +191,6 @@ ph.status "FRONT: $statusFront - ${iFrontend} (max: ${iMaxConnFront}) .. BACK: $
test -z "$statusExt" || echo "${statusExt}" test -z "$statusExt" || echo "${statusExt}"
# echo; echo DEBUG: ; cat $tmpfile # echo; echo DEBUG: ; cat $tmpfile
ph.perfadd "frontend" "${iFrontend}" ph.perfadd "frontend" "${iFrontend}"
ph.perfadd "frontend-max" "${iMaxConnFront}" ph.perfadd "frontend-max" "${iMaxConnFront}"
ph.perfadd "frontend-free" "${iFrontendFree}" ph.perfadd "frontend-free" "${iFrontendFree}"
...@@ -162,11 +206,11 @@ ph.perfadd "backend-free" "${iBackendFree}" ...@@ -162,11 +206,11 @@ ph.perfadd "backend-free" "${iBackendFree}"
getColumn $colCurrentConnections | sed -n "2,$ p" >$tmpfile2 getColumn $colCurrentConnections | sed -n "2,$ p" >$tmpfile2
while read line while read line
do do
srv=$(echo $line | cut -f 1 -d ",") srv=$(echo $line | cut -f 1 -d ",")
val=$(echo $line | cut -f 2 -d ",") val=$(echo $line | cut -f 2 -d ",")
label=$(echo $srv | tr [:upper:] [:lower:]) # label=$(echo $srv | tr [:upper:] [:lower:])
# echo "${srv} - ${val}" # echo "${srv} - ${val}"
echo -n "${srv} - ${val} " echo -n "${srv} - ${val} "
# v1.3: if it is a servername then ping to it # v1.3: if it is a servername then ping to it
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment