2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00
contrib-munin/plugins/haproxy/haproxy_denied_backend
2012-09-17 10:49:02 +02:00

116 lines
2.9 KiB
Bash
Executable File

#!/bin/bash
# -*- bash -*-
: << =cut
=head1 NAME
haproxy_denied_backend -Haproxy Denied 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
# 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
=head1 AUTHOR
Ricardo Fraile <rfrail3@yahoo.es>
=head1 LICENSE
GPLv2
=head1 MAGICK MARKERS
#%# family=auto
#%# capabilities=autoconf
=cut
. $MUNIN_LIBDIR/plugins/plugin.sh
function parse_url {
# Modify ifs variable
OIFS=$IFS;
IFS=",";
PXNAME="$1"
SVNAME="$2"
VALUE="$3"
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
ARRAY1=($LINE1);
# Find values
for ((i=0; i<${#ARRAY1[@]}; ++i));
do
# Get data
if [[ "${ARRAY1[$i]}" == "${VALUE}" ]]; then
o=$i;
o=`expr $o + 1`
echo ${LINE2} | cut -d" " -f $o
fi
done
# Reset ifs
IFS=$OIFS;
}
SVNAME='BACKEND'
LIST="$backend"
if [ "$1" = "autoconf" ]; then
echo yes
exit 0
fi
if [ "$1" = "config" ]; then
echo "graph_title Denied Requests / Responses ${SVNAME}"
echo 'graph_args --base 1000 -l 0 '
echo 'graph_vlabel Requests and Responses'
echo 'graph_scale no'
echo 'graph_category haproxy'
echo "graph_info Denied Requests / Responses ${SVNAME}"
for i in ${LIST}; do
echo "dreq`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.label Denied Requests $i"
echo "dreq`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.type DERIVE"
echo "dreq`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.min 0"
echo "dreq`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.info Denied Requests $i"
echo "dresp`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.label Denied Responses $i"
echo "dresp`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.type DERIVE"
echo "dresp`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.min 0"
echo "dresp`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.info Denied Responses $i"
done
exit 0
fi
for i in ${LIST}; do
DREQ=`parse_url ${i} ${SVNAME} dreq`
DRESP=`parse_url ${i} ${SVNAME} dresp`
echo "dreq`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.value $DREQ"
echo "dresp`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.value $DRESP"
done