How to run stats in HAProxy 1.6.4 on same port as frontend?
Asked Answered
P

3

5

I'm using HAProxy 1.6.4 and want to enable the stats. (/haproxy?stats)

Here is my cfg:

global
   log 127.0.0.1 local2
   daemon
   maxconn 256

defaults
   log global
   timeout connect  5000
   timeout client  10000
   timeout server  10000

frontend http-in
   bind *:8080
   default_backend testb

backend testb
   balance roundrobin
   server s1 123.456.789.0:443 maxconn 32
   server s2 123.456.789.1:443 maxconn 32

listen statistics
   bind *:8080
   mode http
   stats enable

If I run statistics on other port than 8080 it works, but how can I run it on the same port as my frontend (8080), which is running in the default mode tcp?

Pornocracy answered 13/4, 2016 at 12:47 Comment(0)
M
7

You can do it by redirecting to your self and using access list like this:

global
   log 127.0.0.1 local2
   daemon
   maxconn 256

defaults
   log global
   timeout connect  5000
   timeout client  10000
   timeout server  10000

listen stats :1936
   mode http
   stats enable
   stats hide-version
   stats realm Haproxy\ Statistics
   stats uri /
   stats auth myUser:myPassword

frontend http-in
   bind *:8080
   acl is_www hdr_end(host) -i www.mysite.com
   acl is_stat hdr_end(host) -i stat.mysite.com  

   use_backend srv_www if is_www
   use_backend srv_stat if is_stat

backend srv_www
   balance roundrobin
   server s1 123.456.789.0:443 maxconn 32
   server s2 123.456.789.1:443 maxconn 32

backend srv_stat
   server Local 127.0.0.1:1936

When going to your server with www, it takes you to the web server. But using stat, it redirects you from your input port 8080 to 1936 whee stat is running

Margaritamargarite answered 28/4, 2016 at 10:44 Comment(3)
I don't think this is appropriate syntax for haproxy 1.6. 'listen' cannot handle unexpected argument ':1936'Loy
command haproxy -c -f haproxy.cfg using above file in haproxy 1.7 results: [ALERT] 095/154845 (1343) : Error(s) found in configuration file : haproxy.cfgHyacinthhyacintha
@JoelHandwell in the new HAProxy version 1.6.5 the syntax has changed superuser.com/questions/1080306/haproxy-configuration-errorsGare
S
0

This is just an educated guess. You can't serve the stats page in tcp mode because it's proxying at layer4. In this mode, haproxy only knows IPs and ports from incoming packets and routes it accordingly based on defined rules.

Unlike http mode (layer7), it has more info to work on like HTTP headers where path is available and use it to know when to serve the /haproxy?stats page.

Snuffbox answered 18/4, 2016 at 7:43 Comment(0)
B
0

If you are happy to use a your path, it really easy. this should work

global
   log 127.0.0.1 local2
   daemon
   maxconn 256

defaults
   log global
   timeout connect  5000
   timeout client  10000
   timeout server  10000

frontend http-in
   bind *:8080

   stats enable
   stats uri /stats

   default_backend testb

backend testb
   balance roundrobin
   server s1 123.456.789.0:443 maxconn 32
   server s2 123.456.789.1:443 maxconn 32

you can then access the haproxy stats from http://< hostname >:8080/stats

(tested on haproxy 2.5.5)

Brusquerie answered 18/5, 2022 at 0:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.