Verifying hosts are active in the load balancer pool

January 11, 2012 Pivotal Labs

Most load balancers have a heart beat monitor, that allows the load balancer to decide whether or not to send traffic to a given host.

For example:

http://server1.host.com/check.txt

If the load balancer gets a 200, it will send traffic to server1, if it gets a 404 or a timeout, it will not.

Today we were trying to figure out how to find what servers were up and running in the load balancer pool.

Here’s the capistrano task we came up with:

desc "Curls the check.txt file to see if the host is in the load balancer"
  task :check_load_balancer do
    roles[:web].map(&:host).each do |hostname|
      value = %x{/usr/bin/curl -fs 'http://#{hostname}/check.txt'}
    puts "Curling http://#{hostname}/check.txt: #{value}"
  end
end

This gives you output like the following:

$ cap production deploy:check_load_balancer
  * executing `production'
  * executing `deploy:check_load_balancer'
Curling http://server2.dc1.domain.com/check.txt:
Curling http://server3.dc1.domain.com/check.txt: OK
Curling http://server4.dc1.domain.com/check.txt: OK
Curling http://server5.dc1.domain.com/check.txt:
Curling http://server6.dc1.domain.com/check.txt: OK
Curling http://server7.dc1.domain.com/check.txt: OK
Curling http://server8.dc1.domain.com/check.txt: OK
$

Now we can easily see there are issues with server 2 and 5.

About the Author

Biography

Previous
Whistlestop.com is looking for a Senior RoR Developer
Whistlestop.com is looking for a Senior RoR Developer

At Pivotal Labs, one of the services we provide our clients is helping them interview and hire. Pivotal Lab...

Next
Unpakt is looking for a Lead Ruby on Rails Developer
Unpakt is looking for a Lead Ruby on Rails Developer

At Pivotal Labs, one of the services we provide our clients is helping them interview and hire. Pivotal Lab...