Home Depot carries a moisture sensor for about $14 that you put in the drain pan. You will find this in the plumbing department near the water heaters. This unit takes a 9-volt battery (which lasts about 2 years) the sensor will go off just by detecting the moisture on the palm of your hand. The problem is if the unit is in the 2nd-floor attic you may not hear the alarm. If you are out of town when the water heater breaks this will be of no use.
There are sensors that allow you to mount the sensor in the pan and the alarm somewhere else in the home so that you will be sure to hear it. Search the internet.
There are sensors that will send you a text message to your phone (you will have to search the internet) but if you are out of town you may be in a pickle!
The Floodstop sensor turns the water off to the tank. The part is about $120.00 http://www.getfloodstop.com/
The Taco sensor model WAGS7200-2 turns the water off to the tank and the gas pilot off. The part is about $160.00 WAGS stands for Water And Gas Safety Valve. The Taco WAGS valve is designed to shut off the water supply plus gas supply (for gas-fired heaters) in the event of a leaking water heater, thus minimizing water damage and creating a safe fuel gas condition.
Installation guide double click on the picture to open: