2012-09-11 10:53:58 +02:00
|
|
|
#!/bin/bash
|
|
|
|
# -*- bash -*-
|
|
|
|
|
|
|
|
: << =cut
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
haproxy_responses_backend -Haproxy responses backend
|
|
|
|
|
|
|
|
=head1 CONFIGURATION
|
|
|
|
|
|
|
|
[haproxy*]
|
|
|
|
user root
|
|
|
|
env.backend backend_name_1 backend_name_2 backend_name_3
|
|
|
|
env.frontend frontend_name_1 frontend_name_2 frontend_name_3
|
2012-09-17 10:49:02 +02:00
|
|
|
# You can use url o socket option, use one of them, not both!
|
|
|
|
env.url http://user:passwd@IP:port/admin?stats;csv
|
|
|
|
# or
|
|
|
|
env.socket /var/lib/haproxy/stats.socket
|
2012-09-11 10:53:58 +02:00
|
|
|
|
|
|
|
=head1 AUTHOR
|
|
|
|
|
2012-09-11 13:49:33 +02:00
|
|
|
Ricardo Fraile <rikr_@hotmail.com>
|
2012-09-11 10:53:58 +02:00
|
|
|
|
|
|
|
=head1 LICENSE
|
|
|
|
|
2012-09-14 09:27:38 +02:00
|
|
|
GPLv2
|
2012-09-11 10:53:58 +02:00
|
|
|
|
|
|
|
=head1 MAGICK MARKERS
|
|
|
|
|
|
|
|
#%# family=auto
|
|
|
|
#%# capabilities=autoconf
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
. $MUNIN_LIBDIR/plugins/plugin.sh
|
|
|
|
|
|
|
|
function parse_url {
|
2012-09-11 13:49:33 +02:00
|
|
|
# Modificamos la variable if, al final se vuelve a dejar igual
|
2012-09-11 10:53:58 +02:00
|
|
|
OIFS=$IFS;
|
|
|
|
IFS=",";
|
|
|
|
PXNAME="$1"
|
|
|
|
SVNAME="$2"
|
|
|
|
VALUE="$3"
|
2012-09-17 10:49:02 +02:00
|
|
|
|
|
|
|
if [ ! -z "$url" ]; then
|
|
|
|
LINE1=`curl -s "$url" | head -1 | sed 's/# //'`
|
|
|
|
LINE2=`curl -s "$url" | grep "$PXNAME,$SVNAME"`
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -z "$socket" ]; then
|
|
|
|
LINE1=`echo 'show stat' | socat unix-connect:"$socket" stdio | head -1 | sed 's/# //'`
|
|
|
|
LINE2=`echo 'show stat' | socat unix-connect:"$socket" stdio | grep "$PXNAME,$SVNAME"`
|
|
|
|
fi
|
2012-09-11 10:53:58 +02:00
|
|
|
|
|
|
|
ARRAY1=($LINE1);
|
|
|
|
|
2012-09-11 13:49:33 +02:00
|
|
|
# Recorremos el array buscando los valores esperados
|
2012-09-11 10:53:58 +02:00
|
|
|
for ((i=0; i<${#ARRAY1[@]}; ++i));
|
|
|
|
do
|
2012-09-11 13:49:33 +02:00
|
|
|
# Si coincide con el valor, sacar el dato
|
2012-09-11 10:53:58 +02:00
|
|
|
if [[ "${ARRAY1[$i]}" == "${VALUE}" ]]; then
|
|
|
|
o=$i;
|
|
|
|
o=`expr $o + 1`
|
|
|
|
echo ${LINE2} | cut -d" " -f $o
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2012-09-11 13:49:33 +02:00
|
|
|
# se deja la variable igual
|
2012-09-11 10:53:58 +02:00
|
|
|
IFS=$OIFS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SVNAME='BACKEND'
|
|
|
|
LIST=$backend
|
|
|
|
|
|
|
|
if [ "$1" = "autoconf" ]; then
|
2018-08-02 02:03:42 +02:00
|
|
|
echo yes
|
2012-09-11 10:53:58 +02:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$1" = "config" ]; then
|
|
|
|
|
|
|
|
echo "graph_title HTTP Responses ${SVNAME}"
|
|
|
|
echo 'graph_args --base 1000 -l 0 '
|
|
|
|
echo 'graph_vlabel Responses'
|
|
|
|
echo 'graph_scale no'
|
2017-02-22 03:29:26 +01:00
|
|
|
echo 'graph_category loadbalancer'
|
2012-09-11 10:53:58 +02:00
|
|
|
echo "graph_info HTTP Responses ${SVNAME}"
|
|
|
|
|
|
|
|
for i in ${LIST}; do
|
|
|
|
echo "hrsp_1xx`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.label HTTP 1xx $i"
|
|
|
|
echo "hrsp_1xx`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.type DERIVE"
|
|
|
|
echo "hrsp_1xx`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.min 0"
|
|
|
|
echo "hrsp_1xx`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.info HTTP responses with 1xx code $i"
|
|
|
|
|
|
|
|
echo "hrsp_2xx`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.label HTTP 2xx $i"
|
|
|
|
echo "hrsp_2xx`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.type DERIVE"
|
|
|
|
echo "hrsp_2xx`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.min 0"
|
|
|
|
echo "hrsp_2xx`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.info HTTP responses with 2xx code $i"
|
|
|
|
|
|
|
|
echo "hrsp_3xx`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.label HTTP 3xx $i"
|
|
|
|
echo "hrsp_3xx`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.type DERIVE"
|
|
|
|
echo "hrsp_3xx`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.min 0"
|
|
|
|
echo "hrsp_3xx`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.info HTTP responses with 3xx code $i"
|
|
|
|
|
|
|
|
echo "hrsp_4xx`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.label HTTP 4xx $i"
|
|
|
|
echo "hrsp_4xx`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.type DERIVE"
|
|
|
|
echo "hrsp_4xx`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.min 0"
|
|
|
|
echo "hrsp_4xx`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.info HTTP responses with 4xx code $i"
|
|
|
|
|
|
|
|
echo "hrsp_5xx`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.label HTTP 5xx $i"
|
|
|
|
echo "hrsp_5xx`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.type DERIVE"
|
|
|
|
echo "hrsp_5xx`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.min 0"
|
|
|
|
echo "hrsp_5xx`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.info HTTP responses with 5xx code $i"
|
|
|
|
|
|
|
|
echo "hrsp_other`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.label HTTP other $i"
|
|
|
|
echo "hrsp_other`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.type DERIVE"
|
|
|
|
echo "hrsp_other`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.min 0"
|
|
|
|
echo "hrsp_other`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.info HTTP responses with other codes $i"
|
|
|
|
|
|
|
|
|
|
|
|
done
|
|
|
|
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
for i in ${LIST}; do
|
|
|
|
H1xx=`parse_url ${i} ${SVNAME} hrsp_1xx`
|
|
|
|
H2xx=`parse_url ${i} ${SVNAME} hrsp_2xx`
|
|
|
|
H3xx=`parse_url ${i} ${SVNAME} hrsp_3xx`
|
|
|
|
H4xx=`parse_url ${i} ${SVNAME} hrsp_4xx`
|
|
|
|
H5xx=`parse_url ${i} ${SVNAME} hrsp_5xx`
|
|
|
|
Hoxx=`parse_url ${i} ${SVNAME} hrsp_other`
|
|
|
|
echo "hrsp_1xx`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.value $H1xx"
|
|
|
|
echo "hrsp_2xx`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.value $H2xx"
|
|
|
|
echo "hrsp_3xx`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.value $H3xx"
|
|
|
|
echo "hrsp_4xx`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.value $H4xx"
|
|
|
|
echo "hrsp_5xx`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.value $H5xx"
|
2012-09-11 13:49:33 +02:00
|
|
|
echo "hrsp_other`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.value $Hoxx"
|
2012-09-11 10:53:58 +02:00
|
|
|
done
|
2018-08-02 02:03:42 +02:00
|
|
|
|