You can configure VRRP (Virtual Router Redundancy Protocol) to track connectivity using a simple ping to any outside responder.
The responder may represent the default route of the router, or any device meaningful to network connectivity of the master VRRP router. If pinging the responder consecutively fails the specified number of times, the router automatically relinquishes master status based on the tracking mode.