Look at things like https://www.raspberrypi.org/forums/viewtopic.php?f=91&t=34994 to keep a watch on the temperature and the electricity input the RPi is getting. Trigger a shut-down when the situation is critical