How to get (count of) active backends of HAProxy?

I can monitor HAProxy stats via

listen stats
   stats uri /<URI>

and

curl ../<URI>

I need to get backends info and I’ve searched such way:

echo “show backend” |
sudo socat stdio tcp4-connect:<IP>:<PORT>

but it nothing returns.

Should I define similar section in the HAProxy configuration before using such .. API?

Otherwise there’re no configuration issues and show backend is built-in API endpoint and there’re other problems (user/password maybe)?

So what’s the next steps I need to follow to resolve the issue?

Ok.

I’ve found I’ve been using incorrect .. endpoint (?).

In my case I had to find out stats endpoint during configuration exploring and it’d say me that the socket is /var/run/haproxy.sock.

So:

echo “show backend” | nc -w 10 -U /var/run/haproxy.sock

returns what I want.