I’m looking for a reliable way to log when my laptop is:

  • powered down
  • boots up
  • goes to sleep
  • wakes up

Currently I’m checking both the systemd-suspend and tlp systemctl services, but these don’t really feel very robust, and I don’t have TLP installed on all my machines.

Is there an easier way to do this, or a better systemctl unit that logs all the power states of my machine. Preferably laptop agnostic?

Laptop snippet so far:

journalctl --since -9days -u systemd-suspend -u tlp \
    | grep -P "Finish|Start|Stopped" | sed '/.*Finished TLP.*/d;
            s|Starting TLP.*|╭╴System Boot  |;
 s|Starting System Suspend.*|┤ · Sleep      |;
 s|Finished System Suspend.*|├ · Wake       |;
             s|Stopped TLP.*|╰╴Power Off    |;' \
    | sed -r 's|^(.*:[0-9]+)+:[0-9]+.*:(.*)|   \1 \2 |'
  • limelight79@lemm.ee
    link
    fedilink
    arrow-up
    2
    ·
    10 hours ago

    I’m not clear on your use case here - the system obviously can’t report if it’s off. Initially I thought this was in the Home Assistant community, and I was going to suggest just pinging the machine at regular intervals from the HA system. That makes sense if you’re trying to monitor various systems.

    • tetris11@lemmy.mlOP
      link
      fedilink
      arrow-up
      2
      ·
      edit-2
      9 hours ago

      It can report just before it’s shutting down. Hell, if I run shutdown -P 20:00 "OH WE GOIN DOWN" you bet your ass that I will get a wall message on every tty with that message at 8pm.

      I’m just wondering how to reliably capture the shutdown messages without having to scan the entire system log. I just assumed that there would be one service file that I would have to check for these types of events, but apparently the best bet I have is the TLP service daemon which typically only runs on laptops.