#!/bin/bash # -*- bash -*- : << =cut =head1 NAME haproxy_bytes_frontend -Haproxy Bytes Frontend =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 env.url http://user:passwd@IP:port/admin?stats;csv =head1 AUTHOR Ricardo Fraile =head1 LICENSE GNU =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" LINE1=`curl -s "$url" | head -1 | sed 's/# //'` LINE2=`curl -s "$url" | grep "$PXNAME,$SVNAME"` 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='FRONTEND' LIST=$frontend if [ "$1" = "autoconf" ]; then echo yes exit 0 fi if [ "$1" = "config" ]; then echo "graph_title Bytes ${SVNAME}" echo 'graph_args --base 1000' echo 'graph_vlabel Bytes in (-) / out (+)' echo 'graph_category haproxy' echo "graph_info Bytes ${SVNAME}" for i in ${LIST}; do echo "down`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.label Bytes $i" echo "down`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.type DERIVE" echo "down`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.graph no" echo "down`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.cdef down`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`,8,*" echo "down`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.min 0" echo "up`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.label Bytes $i" echo "up`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.type DERIVE" echo "up`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.negative down`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`" echo "up`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.cdef up`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`,8,*" echo "up`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.info Bytes in $i" echo "up`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.min 0" done exit 0 fi for i in ${LIST}; do BIN=`parse_url ${i} ${SVNAME} bin` BOUT=`parse_url ${i} ${SVNAME} bout` echo "down`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.value $BOUT" echo "up`echo $i | md5sum | cut -d - -f1 | sed 's/ //g'`.value $BIN" done