Honestly, it depends. First, it depends on whether or not the rocket has an automatic self destruct or whether this has to be triggered by someone on the ground, and then it depends on what goes wrong.
The Ariane 5 explosion was triggered by sensors that indicated that the rocket boosters and the core had separated early, indicating that the rocket is breaking apart. In the Titan missile family this is amusingly known as the "Inadvertent Separation Destruct System". NASA requires such a system when solid boosters are used.
Since so much can go wrong on a rocket launch many rockets use a non-autonomous range safety officer who manually issues a destruct command. It appears that autonomous self destruct is a rarity to the extent that it is just being explored by newcomers. SpaceX's system appears to rely mainly on GPS as a sensor, with the understanding being that if something is going wrong then the rocket will be off course.
This article talks about such systems that had been demonstrated as of 2007. Some rockets then used very simple means (such as inertial measurement sensors detecting if yaw or pitch had exceeded expected bounds), and NASA's research into an autonomous system relied primarily on GPS and inertial sensors (accelerometers and gyros).