Alerts and monitoring

Monitor URI

You can use the monitor-uri and monitor fail directives in a frontend section to present a webpage that monitoring software like Nagios, Icinga or others can check periodically to know the state of the load balancer.

Enable the monitoring page Jump to heading

Below, we enable the monitoring webpage:

haproxy
frontend www
bind :80
monitor-uri /checkstatus
monitor fail if { nbsrv(webservers) eq 0 }
default_backend webservers
backend webservers
balance roundrobin
server server1 10.0.1.3:80 check
server server2 10.0.1.4:80 check
haproxy
frontend www
bind :80
monitor-uri /checkstatus
monitor fail if { nbsrv(webservers) eq 0 }
default_backend webservers
backend webservers
balance roundrobin
server server1 10.0.1.3:80 check
server server2 10.0.1.4:80 check

In this example:

  • The monitor-uri directive’s value is a URL path that does not map to any resource on your backend servers. The load balancer will respond with an HTTP 200 OK whenever the monitoring software requests this URL path. In this example, we present a page at /checkstatus that monitoring software can request periodically.
  • The monitor fail directive returns an HTTP 503 Service Unavailable response if a given condition is true. In this case, the condition checks whether the webservers backend has zero healthy servers up.

Use them both together

Always use these two directives together.

  • If you use monitor-uri alone, the monitoring software always receives a 200 OK response, which reveals only that the load balancer is running but does not indicate the health of the backend servers.
  • If you use monitor fail alone, there is no effect.

You can have only one monitor-uri directive, but you can have multiple monitor fail directives, each specifying different conditions.

Do you have any suggestions on how we can improve the content of this page?