Compute InactiveEnterTimestamp - InactiveExitTimestamp
O tempo de ativação (em segundos) é o resultado de:
(ActiveEnterTimestampMonotonic - InactiveExitTimestampMonotonic) / 1e6
Veja a função analyze_plot
no arquivo analyze.c para detalhes.
Mas você deve ter RemainAfterExit=yes
em sua unidade para obter ActiveEnterTimestampMonotonic
.
Você pode calcular ExecMainExitTimestampMonotonic - ExecMainStartTimestampMonotonic
no PostStartExec
sem RemainAfterExit
.
e.g. by reading them through the D-Bus interface in Python.
Você pode usar systemctl
para extrair esses valores:
$ systemctl show -p InactiveExitTimestampMonotonic -p ActiveEnterTimestampMonotonic unit
InactiveExitTimestampMonotonic=44364325621
ActiveEnterTimestampMonotonic=44369331083
De acordo com a Promessa de estabilidade da interface :
The stable interfaces are:
...
The command line interface of systemctl, loginctl, journalctl.
We will make sure that scripts invoking these commands will continue
to work with future versions of systemd. Note however that the output
generated by these commands is generally not included in the promise,
unless it is documented in the man page. Example: the output of
"systemctl status" is not stable, but the one of "systemctl show" is,
because the former is intended to be human readable and the latter
computer readable, and this is documented in the man page.
My end goal is to be able to monitor how much time each service activation takes, and be alerted if it takes too long
Você pode definir TimeoutStartSec e OnFailure :
TimeoutStartSec=
Configures the time to wait for start-up. If a daemon service does
not signal start-up completion within the configured time, the
service will be considered failed and will be shut down again.
OnFailure=
A space-separated list of one or more units that are activated when
this unit enters the "failed" state.
or hasn't run for a long time
Você pode extrair o último tempo de sucesso do diário:
journalctl -u your-service MESSAGE='Started your-service.service.'
Mas você deve ativar o armazenamento persistente de mensagens de log.