I'd like to be able to retrieve from systemd how much time the last activation of a oneshot
service took. I thought about the following options, but they didn't manage to convince me completely :
Compute
InactiveEnterTimestamp - InactiveExitTimestamp
, e.g. by reading them through the D-Bus interface in Python. This has the disadvantage of being inconsistent (=negative) while the service is running.Use helper scripts in
ExecStartPre
andExecStartPost
to store a timestamp and compute the elapsed time once the service exits.Use a wrapper script around the service executable that stores the elapsed time somewhere on the filesystem once the main executable exits.
Use an helper script in
ExecStartPost
that stores the value computed in #1.
My preference goes to #4 if possible, then #3 if not. What would you suggest? Is there a better way of doing this?
Background: I am running Tiny Tiny RSS, which has a feed updater script that I run at regular intervals using a systemd timer. I also run Isync the same way to backup the contents of my Gmail inbox. My end goal is to be able to monitor how much time each service activation takes, and be alerted if it takes too long or hasn't run for a long time.
EDIT: My service file looks like this:
[Unit]
Description=Tiny Tiny RSS feeds update
After=network.target mysqld.service postgresql.service
[Service]
Type=oneshot
ExecStart=/usr/bin/php /usr/share/webapps/tt-rss/update.php --feeds
User=ttrss
StandardOutput=syslog
StandardError=syslog
And this is the timer:
[Unit]
Description=Tiny Tiny RSS feeds update timer
[Timer]
OnBootSec=1s
OnUnitInactiveSec=120s
Persistent=true
Unit=tt-rss.service
[Install]
WantedBy=timers.target
RemainAfterExit=yes
: This prevents the timer from starting the service periodically, so I suppose I'm not supposed to use it that way? – F.X. Oct 07 '15 at 19:29systemctl show
: Is the output format supposed to be stable enough that I can parse it and use it? – F.X. Oct 07 '15 at 19:38analyze_plot
! I'll look into it a little bit later so I can see how it's used in real code by people that know what they are doing with systemd :) – F.X. Oct 07 '15 at 19:39ExecMainExitTimestampMonotonic - ExecMainStartTimestampMonotonic
in thePostStartExec
withoutRemainAfterExit
– Evgeny Oct 07 '15 at 21:05tt-rss.d
directory so that I can easily copy the same snippet to another service. Will post updates when I get that working. – F.X. Oct 07 '15 at 21:16