[Rdo-list] How to know which galera server haproxy is pointing in an overcloud HA env

Ryan O'Hara rohara at redhat.com
Mon Oct 12 23:03:01 UTC 2015


B1;4002;0cOn Thu, Oct 08, 2015 at 04:15:59PM +0200, Raoul Scarazzini wrote:
> Il giorno 7/10/2015 17:21:11, Marius Cornea ha scritto:
> > I was just suggesting a way to see to which of the backend nodes
> haproxy is directing the traffic. Please see the attachment.
> 
> Thanks again Marius,
> from your point of view, does this script make sense?
> 
> #!/bin/bash
> 
> # haproxy bind address
> VIP=$1
> 
> # Associative array for controller -> bytes list
> declare -A controllers
> 
> function get_stats {
>  # 2nd field -> controller name | 10th field -> bytes in | 11th field ->
> bytes out
>  stats=$(echo "show stat" | socat /var/run/haproxy stdio | grep
> mysql,overcloud | cut -f2,10 -d,)
> }
> 
> get_stats
> 
> # Put the first byte values in the array
> for line in $stats
> do
>  controller=$(echo $line | cut -f1 -d,)
>  controllers[$controller]=$(echo $line|cut -f2 -d,)
> done
> 
> # Do something (nothing) on the VIP's db
> mysql -u nonexistant -h $VIP &> /dev/null
> 
> get_stats
> 
> # Compare the stats the one different is the master
> for controller in ${!controllers[@]}
> do
>  value2=$(echo "$stats"|grep $controller|cut -f2 -d,)
>  [ ${controllers[$controller]} -ne $value2 ] && echo "$controller is
> MASTER" || echo "$controller is slave"
> done
> 
> I know it's ugly, but since we don't have any other method to get those
> informations I don't see any other solution. Of course it can be adapted
> to get values from http instead of the socket (that by default is not
> enabled).
> 
> What do you think?

Why not just send a query to the database VIP to get the hostname?

Ryan




More information about the dev mailing list