3

I can list past boots of my machine with journalctl --list-boots. The output looks something like this:

 -4 21b1318cbaf04732b95ed0a5e40f6698 Tue 2019-06-25 17:26:53 CEST—Fri 2019-07-05 17:11:31 CEST
 -3 02d30049fdef4a809122f499ef95d122 Fri 2019-07-05 17:12:33 CEST—Wed 2019-08-14 10:23:47 CEST
 -2 aedc9088bd0a4a9588c387e593c9cc25 Wed 2019-08-14 10:24:41 CEST—Fri 2019-09-20 16:28:12 CEST
 -1 e40c23b16b86400292b7da77f03f677f Fri 2019-09-20 16:29:03 CEST—Mon 2019-10-07 16:31:20 CEST
  0 973dc1142add4a249e784c1a68fac31a Mon 2019-10-07 16:32:11 CEST—Tue 2019-10-15 12:12:22 CEST

So I can use this to find out when the computer was booted and when it was shut down.

I want to have the same information for a single systemd unit (in my case a .service). But I did not find a way to get this information. The obvious journalctl -u foo.service returns lines like these:

Oct 10 00:00:01 localhost systemd[1]: Started foo service.
Oct 10 00:00:02 localhost foo[19382]: some foo output
Oct 10 00:00:02 localhost foo[19382]: some foo output
Oct 10 00:00:02 localhost foo[19382]: some foo output
Oct 10 00:00:02 localhost foo[19382]: some foo output
Oct 10 00:00:02 localhost foo[19382]: some foo output
Oct 10 00:00:02 localhost foo[19382]: some foo output
Oct 10 00:11:22 localhost foo[19382]: some foo output
Oct 10 12:00:01 localhost systemd[1]: Started foo service.
...

From this I can find out that the service was started on 00:00:01 and again on 12:00:01 but I do not know how long it ran for exactly (only that it ran at least until 00:11:22).

Background: I want to find out if the service (a backup script in my case) did take more or less time in the past.

1 Answer 1

1

I thought systemd-analyze may be the answer, but it doesn't look that way.

There's a LOT it seems able to do, but the functionality deals more with "how long did services take to start", not "how long did they run for". The latter might not be something it does. systemd-analyze plot > plot.svg outputs an SVG bar chart of units' start times (time spent initializing highlighted), but, again, it doesn't seem to support "finish times" (some bars are cut off early, but it's unclear whether that means their service finished at the cut-off point) or made to support processes running intermittently on the same boot...

Luckily, since the service you're concerned with is your own, you could modify it and add "Started @" and "Finished @" messages that can be read with journalctl -u foo.service or write to a log file.

For general services that you don't feel comfortable modifying, though, other answers needed.

1
  • 1
    I would consider modifying the command in the service a last resort even for my custom units as it does not "backport" to the past: I can not find out what happend yesterday before I implemented this extra logging in my service. So I have to implement it in every where I might ever be interested in the running time.
    – Lucas
    Oct 16, 2019 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.