I know this is an old post but, if anyone else is looking to do something similar i.e.: Count the number of active conections on a server, and when it hits a threshold notify HAProxy to drain connections... Thats exactly what the open source agent from Loadbalancer.org does... And it has both a Linux and Windows version.