For boot and power down, create a service to log it.
For the others, an elogind script might be what you look for.
From Wikipedia, the free encyclopedia
Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).
Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.
Community icon by Alpár-Etele Méder, licensed under CC BY 3.0
For boot and power down, create a service to log it.
For the others, an elogind script might be what you look for.
Are you asking about uptime monitoring on a remote host, or the actual last state of the machine once X happens via logged info on the machine?
If the former, you can add a hook that pings somewhere before X action takes place.
For the latter, it should be in dmesg, both going not and coming out of different states.
I guess uptime monitoring of any host, with specific timestamps for when the system is suspended/resumed.
(Yes I understand that a server ideally shouldn't sleep)
in your shoes i would use a loop to iterate through journalctl's up/down sessions getting the first and last lines of each and then use awk to printout the timestamps and sed to add in power state changes.