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 :
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
ExecStartPostto 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
ExecStartPostthat 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