1

Specifically in Varnish 3, is there a way to check if a director has any healthy backends?

My use case is that I have a load balancer that is distributing traffic to 2 varnish boxes, which in turn are sitting in front of several web servers. I want Varnish to return a 200 to the load balancer's health check if the director has at least one healthy backend, without depending on passing the request through to an actual backend.

I'm looking for something like:

if (req.url ~ "healthcheck.html") {
    if (my_director.has_healthy_backend) {
        return 200
    } else {
        error 500 "No backends available"
    }
}
2

The main thing is that you have your director set up with probing, so it actually has a health status on your backends. If that is the case, then you could just use something like the following:

sub vcl_recv {
    if (req.url ~ "healthcheck.html") {
        if (!req.backend.healthy) {
            error 503 "No backends available";
        } else {
            error 200 "All is well";
        }
    }
    [...rest of your logic...]
|improve this answer|||||
0

The equivalent Varnish 4 solution is:

if (req.url ~ "healthcheck.html") {
  if (!std.healthy(req.backend_hint)) {
    return (synth (503, "No backends available"));
  }
  else {
    return (synth (200, "All is well"));
  }
}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.