システムサービスの起動時間の監視

システムサービスの起動時間の監視

oneshotサービスを最後にアクティブ化するのにかかった時間をsystemdで検索したいと思います。私は次のオプションを考えましたが、あまり説得力がありませんでした。

  1. たとえば、Compute はInactiveEnterTimestamp - InactiveExitTimestampPython の D-Bus インターフェイスを介して読み込みます。これの欠点は、サービスの実行中に一貫性がないことです(=否定的です)。

  2. ExecStartPreとのヘルパースクリプトを使用してExecStartPostタイムスタンプを保存し、サービス終了後の経過時間を計算します。

  3. デフォルトの実行可能ファイルが終了したら、ファイルシステムのどこかに経過時間を格納するサービス実行可能ファイルの周りにラッパースクリプトを使用します。

  4. ヘルパースクリプトを使用してExecStartPost#1で計算された値を保存します。

可能であれば4番を好み、そうでなければ3番を好みます。どんな提案がありますか?もっと良い方法がありますか?

背景:私は走っている小さなRSS、ここにはシステムタイマーを使用して定期的に実行するフィード更新スクリプトがあります。私も走る同期同じ方法でGmailの受信トレイの内容をバックアップしてください。私の究極の目標は、各サービスがアクティブになるのにかかる時間を監視し、サービスが長すぎるか長期間実行されない場合に警告を出すことです。

編集:私のサービスファイルは次のとおりです。

[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

タイマーは次のとおりです。

[Unit]
Description=Tiny Tiny RSS feeds update timer

[Timer]
OnBootSec=1s
OnUnitInactiveSec=120s
Persistent=true
Unit=tt-rss.service

[Install]
WantedBy=timers.target

ベストアンサー1

InactiveEnterTimestampの計算 - InactiveExitTimestamp

アクティベーション時間(秒)は次のように計算されます。

(ActiveEnterTimestampMonotonic - InactiveExitTimestampMonotonic) / 1e6

analyze_plotファイルの関数の表示分析.cもっと学ぶ。

しかし、あなたはそうしなければなりません。RemainAfterExit=yesあなたの家から受け取ってくださいActiveEnterTimestampMonotonic

ExecMainExitTimestampMonotonic - ExecMainStartTimestampMonotonicPostStartExecなしで計算できますRemainAfterExit

たとえば、PythonのD-Busインターフェースを介してお読みください。

systemctl以下を使用してこれらの値を抽出できます。

$ systemctl show -p InactiveExitTimestampMonotonic -p ActiveEnterTimestampMonotonic unit
InactiveExitTimestampMonotonic=44364325621
ActiveEnterTimestampMonotonic=44369331083

~によるとインターフェース安定性の約束:

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.

私の究極の目標は、各サービスがアクティブになるのにかかる時間を監視し、長すぎる場合に警告を送信することです。

設定できますタイムアウト開始秒そして失敗した場合:

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.

それとも長い間走らなかった

ログから最後の成功時間を抽出できます。

 journalctl -u your-service MESSAGE='Started your-service.service.'

しかし、あなたはそうしなければなりません。〜できるようにするログメッセージの継続的な保存。

おすすめ記事