Monitor URI
You can use the monitor-uri
and monitor fail
directives in a frontend
or listen
section to present a webpage that monitoring software like Nagios, Incinga or others can check periodically to know the state of the load balancer.
Enable the monitoring page
In a frontend
or listen
section, add a monitor-uri
directive. Its value is a URL path that does not map to any resource on your backend servers. HAProxy Enterprise will respond with an HTTP 200 OK whenever a client requests that path.
Then, use monitor fail
to return an HTTP 503 Service Unavailable response if a given condition is true.
In this example, we present a page at /checkstatus that monitoring software can request periodically.
frontend www
bind :80
monitor-uri /checkstatus
monitor fail if { nbsrv(webservers) eq 0 }
default_backend webservers
backend webservers
balance roundrobin
cookie SERVERUSED insert indirect nocache
option httpchk HEAD /
default-server check maxconn 20
server server1 10.0.1.3:80 cookie server1
server server2 10.0.1.4:80 cookie server2
The page returns an OK message until the if statement on the monitor fail
line becomes true. In this case, the expression uses the nbsrv
fetch method to check the number of servers that are up in the webservers backend. It returns true when there are zero servers up.
Next up
Integrations