Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 407
zypro Avatar asked Apr 13 '16 12:04

zypro


People also ask

How do I monitor traffic on HAProxy?

The best way to ensure proper HAProxy performance and operation is by monitoring its key metrics in three broad areas: Frontend metrics such as client connections and requests. Backend metrics such as availability and health of backend servers. Health metrics that reflect the state of your HAProxy setup.

What is frontend in HAProxy?

When HAProxy Enterprise is used as a reverse proxy in front of your backend servers, a frontend section defines the IP addresses and ports that clients can connect to. You may add as many frontend sections as needed to expose various websites or applications to the internet.

What is HAProxy session rate?

Session Rate [rate] This is the rate at which HAProxy creates the connections between the frontend and the client. One session can be mapped to a unique client. These are TCP sessions created by each client, over which multiple HTTP requests can be sent.


1 Answers

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

like image 50
Jotne Avatar answered Nov 01 '22 15:11

Jotne