Skip to content

Plugin haproxy stat.sh

Florian Forster edited this page Nov 21, 2023 · 1 revision

Name:

haproxy-stat.sh plugin

Type:

read

Callbacks:

n/a

Status:

external

FirstVersion:

n/a

Copyright:

2010 Oleg Blednov

License:

Manpage:

n/a

See also:

List of Plugins

haproxy-stat.sh is a shell script which reads performance statistics from HAProxy, a free open-source load-balancing software for HTTP and TCP. The script requires the Exec plugin to run and was written by Oleg Blednov.

Code

 #!/bin/sh

 sock='/var/run/haproxy-stat'
 host="${COLLECTD_HOSTNAME}"
 pause="${COLLECTD_INTERVAL:-10}"

 while getopts "h:p:s:" c; do
    case $c in
        h)  host=$OPTARG;;
        p)  pause=$OPTARG;;
        s)  sock=$OPTARG;;
        *)  echo "Usage: $0 [-h <hostname>] [-p <seconds>] [-s <sockfile>]";;
    esac
 done

 while [ $? -eq 0 ]; do
    time="$(date +%s)"
    echo 'show stat' | socat - UNIX-CLIENT:$sock \
    |while IFS=',' read pxname svname qcur qmax scur smax slim stot bin bout dreq dresp ereq econ eresp wretr wredis status weight act bck chkfail chdown lastchg downtime qlimit pid iid sid throttle lbtot tracked type rate rate_lim rate_max check_status check_code check_duration hrsp_1xx hrsp_2xx hrsp_3xx hrsp_4xx hrsp_5xx hrsp_other hanafail req_rate req_rate_max req_tot cli_abrt srv_abrt; do
        [ "$svname" != 'BACKEND' ] && continue
        echo "PUTVAL $host/haproxy/haproxy_backend-$pxname $time:${stot:-0}:${econ:-0}:${eresp:-0}"
    done
    sleep $pause
 done

You can use any combination of HAProxy parameters (see read command in inner while loop).

Synopsis

To use this script add the following line to the configuration of the Exec plugin:

 Exec "haproxy:haproxy" "/etc/collectd/haproxy-stat.sh" \
      "-s" "/var/run/haproxy-stat" "-h" "localhost" "-p" "10"

And add next type in types.db:

haproxy_backend   stot:COUNTER:0:U, econ:COUNTER:0:U, eresp:COUNTER:0:U

Example graphs

Haproxy-stat.jpg

Dependencies

See also

Clone this wiki locally