How to verify if a reboot was due to power outage?-Collection of common programming errors

Your boxes are not connected to UPS? If you do so, usually there is a logging and support for this and you will clearly see when power is going down on UPS and when server is going down due to ups secure shutdown. Maybe you will be interrested into this question: http://unix.stackexchange.com/questions/13714/how-to-properly-prepare-a-server-for-power-outages7

When there is not any UPS it is hard to “write a log” when there is no power. This is impossible. You can find power outage indirectly to cut out other reasons.

I recommend to monitor all important parameters of your boxes to decide, what is shutting down your system. Can be a component failure as mainboard or memory (usually some bluescreens/mem michmatched), or CPU and fans (overheating ends up in shutdown), or HDD r/w errors (bad clusters on system resources), each has some typical symptoms.

Look into /var/log/syslog /var/log/kern.log if there is something interesting.

Power outage can be recorded in system BIOS. You can try to read system BIOS log, if there is any, but it would be elaboration as each server is different in that manner. But this will not necessary tell you what is going on and what is the reason of “server switches off”. Try dmidecode command to get BIOS details, but I doubt there will be a log.

or.. if you don’t want to invest into UPS, you can at least monitor the power line via on-site notebook (has baterry and can read and log the power manager status) try to log a grep ‘Adapter’ from acpi -V, as it should write something like Adapter 0: on/off-line

acpi -V |grep 'Adapter'