Recently my iMac has somehow turned off when I am away for a bit (not sure time length as I didn't notice).

Tapping on keyboard and mouse result in nothing. Have to hit the power button to turn it back on.

Could it be the power supply?

What can I do to check?