ヘルスモニター(HM)は、各仮想マシン(VM)で実行される SDV エージェントです。サービス バンドルの状態を追跡し、VM の健全性を判断して、VM の健全性レポートを定期的に生成します。
OEM 定義のサービス バンドルは、HM によって報告されるさまざまなヘルスシグナルをリッスンし、そのデータに基づいて復元アクションを実行する必要があります。たとえば、サービス バンドルがクラッシュしている SDV インスタンスは、再起動または更新が必要になる場合があります。
HM エージェントを構成して、次の項目を追跡できます。
- 定期的なタスクを実行するエンティティの生存ステータス。生存ハートビートをモニタリングします。このモニタリングは、サービス バンドル インスタンスとカスタム OEM エージェントの両方で構成できます。
- サービス バンドル インスタンスの復元状態。クラッシュ時に自動的に再起動するようにサービス バンドルを構成できます。HM は、この復元プロセスをモニタリングするためのシグナルを提供します。
- 通信 QoS
- SDV と OEM のカスタム エージェントの生存性
参考までに、proto 定義を含む完全な VSIDL カタログは //system/software_defined_vehicle/health_monitor/catalog/health_monitor.vsidl で入手できます。
クイック リファレンス
次の表に、このページで説明する Health Monitor の機能、protobuf スキーマ、RPC サービス、デバッグ コマンドの概要を示します。
| 機能またはワークフロー | 重要なメッセージ、API、コマンド | セクション |
|---|---|---|
| 基本コンセプトと用語 | 生存ハートビート、QoS ハートビート、サービス バンドル復元モニタリング、エージェント クラッシュ モニタリング、VM ヘルスレポートの定義。 | 用語 |
| VM 全体とバンドルごとの構成 | VM レポートの周期(period_ms、推奨値 100 ms)と persist.sdv.health_monitor.config_path の monitored_agent エントリ、およびオプションのバンドルごとの ServiceBundleHealthConfiguration ファイル(health_config_path)を構成します。 |
HM システムを構成する |
| ヘルスレポートとスナップショット RPC クエリ | 定期的な VmHealth ステータス トピックを公開し、HealthMonitorService(ListAllServiceBundles、ListCrashingServiceBundles、ListRecoveringServiceBundles、ListUnhealthyMonitoredServiceBundles、ListQosViolations)を介してオンデマンドの違反クエリを公開します。 |
HM 出力をリッスンすると HM RPC API |
| 生存ハートビート モニタリング | initial_delay_ms、period_ms、num_periods、task_duration_ms に対する定期的な ServiceHeartbeat パブリケーションを追跡します。HealthMonitorRegistrationService を介した明示的な RPC 登録は任意です。 |
生存ハートビートのモニタリングとサービス バンドルに生存ハートビートのモニタリングを追加する |
| 通信 QoS のモニタリング | リスナーが公開した QosHeartbeat メッセージ(timestamp と data_timestamp)を使用して、メッセージ期間(qos_period_threshold_ms)とインフライト レイテンシ(qos_latency_threshold_ms)を確認します。 |
QoS モニタリングと通信に QoS モニタリングを追加する |
| 復元とエージェントのクラッシュのモニタリング | Orchestrator のクラッシュ復旧の失敗を受動的に追跡し、Binder linkToDeath(BinderServiceAgent)を介して重要な SDV エージェントとカスタム OEM エージェントをモニタリングします。 |
サービス バンドルの復元モニタリングとエージェントのクラッシュ モニタリング |
ランタイム検査(dumpsys) |
adb shell dumpsys com.google.sdv.ISdvAgent/hm を使用して、アクティブなハートビート、QoS、エージェント、復元モニターの状態を表示します。 |
稼働状況のモニタリングをデバッグする |
用語
このページでは以下の用語を使用します。
HM サブシステムを操作する
HM 機能を使用するには、OEM の実装で次のことを行う必要があります。
- HM システムを構成するの説明に従って構成ファイルを提供し、ヘルス モニタリング システムを構成します。
- OEM 定義の HM リスナー サービス バンドルを使用して、HM 出力をリッスンし、適切なアクションを実行します。
- ヘルス構成に従って、シグナルを積極的に公開するサービス バンドルを開発します。このパブリケーションにより、HM はヘルス状態を評価できます。詳細については、サービス バンドル開発ガイドをご覧ください。
HM システムを構成する
HM 関連の構成は、次のいずれかの構成タイプにあります。
- VM ごとのグローバルな健全性構成
- サービス バンドルごとのヘルス構成。バンドルのすべてのインスタンスのヘルス パラメータを定義します。
VM ごとの健全性構成
実行時に、HM エージェントは VM 全体のヘルス構成を想定します。これは、//system/software_defined_vehicle/health_monitor/catalog/health_monitoring_config.proto で定義された VMHealth タイプの textproto ファイル(拡張子は .textproto)です。VM Health 構成は、起動時のシステム プロパティ androidboot.sdv.health_monitor.config_path を使用して指定されたパスに配置する必要があります。または、persist.sdv.health_monitor.config_path システム プロパティをカスタムパスに設定することで、実行時に動的に構成することもできます。persist.* 設定は androidboot.* 設定よりも優先されます。新しい構成を有効にするには、デバイスを再起動する必要があります。
VM の健全性構成では、次の設定を行うことができます。
period_msを介した VM ヘルスレポートの周期。この設定は、健全性違反の検出を迅速に通知することと、HM サブシステムのパフォーマンスとのトレードオフになります。100 ミリ秒の値をおすすめします。クラッシュ モニタリングの対象となるエージェント(エージェントのクラッシュ モニタリングを参照)。
構成ファイルの例は //system/software_defined_vehicle/health_monitor/src/prod_configs/ にあります。以下に示すのは、構成ファイルの例です。
period_ms: 100
monitored_agent {
agent_name: "sdv_dt_agent"
binder_interface_name: "google.sdv.data_tunnel.IAgentService/default"
}
monitored_agent {
agent_name: "sdv_rpc_agent"
binder_interface_name: "google.sdv.rpc.IRpcAgent/default"
}
この例では、SDV DT エージェントと RPC エージェントがクラッシュ モニタリング用に構成され、VM のヘルスレポートが 100 ミリ秒ごとに公開されるように構成されています。
サービス バンドルごとの構成
サービス バンドル インスタンスのヘルス モニタリングは任意です。オプトインするには、サービス バンドルの APEX にヘルス構成ファイルを保存し、sdv_service_bundles_manifest.textproto の sdv_service_bundle_metadata の health_config_path フィールドにそのパスを定義します。サービス バンドル マニフェストの詳細については、サービス バンドルのメタデータをご覧ください。
ヘルス構成ファイルは、次のタイプの textproto ファイルです。
message ServiceBundleHealthConfiguration {
// Required: An empty ServiceBundleHealthConfiguration is equivalent to no
// implicit health monitoring or QoS monitoring configured.
//
// Key should contain the instance name that the `InstanceConfiguration` applies to.
map<string, InstanceConfiguration> instance_config = 1;
}
インスタンスごとに、生存ハートビート構成と QoS 構成の両方を指定できます。
// Service bundle *instance* configuration.
message InstanceConfiguration {
// Optional.
//
// Instance health monitoring configuration. Monitors instance
// general health. Well suited for bundles executing periodic tasks.
optional HealthConfiguration health_config = 1;
// Optional.
//
// Map defining the QoS monitoring profile of the instance.
// The key (string) is the topic name of the specific QoS heartbeat
// publication. Choose a meaningful topic name for
// expressive HM reporting.
//
// Only one publisher should publish on this topic. The HM
// agent ignores all publishers except the first one registered
// by the service bundle instance configured for QoS monitoring.
map<string, QosMonitoringConfiguration> qos_config = 2;
}
機能ごとの構成の詳細については、生存ハートビートのモニタリングと QoS モニタリングをご覧ください。
HM 出力を聞く
HM は、定期的なレポートまたは RPC API を介してリッスンできます。
VM の健全性レポート
ヘルス モニタリングでは、高頻度の定期的な VM ヘルスレポートが生成され、モニタリング対象のエンティティの健全性に関する簡潔な情報が提供されます。
VmHealth の型構文は //system/software_defined_vehicle/health_monitor/catalog/health_topic.proto で定義されています。
message VmHealth {
// Required.
// Describes if all monitored service bundles are healthy and report heartbeats on time.
bool all_monitored_service_bundles_healthy = 1;
// Required.
// Describes if all service bundles which should be running on the VM are alive.
bool all_service_bundles_alive = 2;
// Required.
// Indicates if QoS requirements for all service bundles which should be running
// on the VM are satisfied.
bool qos_violations_detected = 3;
}
OEM 定義の HM リスナー サービス バンドルは、VMHealth レポートをリッスンし、システム アーキテクチャ全体に応じて適切なアクションを実行する必要があります。次のような対応が考えられます。
- VM で診断ルーティンを実行します。
- VM を再起動します。
- テレメトリ キャンペーンを実行して原因を特定します。
- システムを更新するか、システムが正常に機能していない場合は更新を停止します。
HM RPC API
VM ヘルスレポートは、頻度と送信速度を最適化したパブリケーションであり、システムのヘルス ステータスに関する幅広い情報を提供します。
HM RPC API を使用すると、HM リスナーはヘルス違反の発生元に関する詳細情報を取得できます。インターフェースは //system/software_defined_vehicle/health_monitor/catalog/health_monitor_service.proto で定義されています。便宜上、インターフェースを以下に示します。
// RPC Interface of the VM Health Monitor Agent for querying details about the current VM
// health.
//
// An OEM-defined service bundle typically monitors the overall health of the SDV instance by listening to
// high-frequency `VMHealth` publication. If violations are detected, this RPC interface can
// be used to retrieve detailed information about the malfunctioning component.
service HealthMonitorService {
// Returns the list of running SDV service bundles that were created or started
// by the orchestrator on this VM.
rpc ListAllServiceBundles(ListAllServiceBundlesRequest) returns (ListAllServiceBundlesResponse) {}
// Returns the list of crashed SDV service bundles.
rpc ListCrashingServiceBundles(ListCrashingServiceBundlesRequest)
returns (ListCrashingServiceBundlesResponse) {}
// Returns the list of recovering SDV service bundles.
rpc ListRecoveringServiceBundles(ListRecoveringServiceBundlesRequest)
returns (ListRecoveringServiceBundlesResponse) {}
// Returns the list of monitored SDV service bundles, which registered for reporting
// aliveness heartbeats but failed to report heartbeats on time.
rpc ListUnhealthyMonitoredServiceBundles(ListUnhealthyMonitoredServiceBundlesRequest)
returns (ListUnhealthyMonitoredServiceBundlesResponse) {}
// Returns a list of QoS monitoring violations detected.
// Provides a snapshot of the current system state.
rpc ListQosViolations(ListQosViolationsRequest)
returns (ListQosViolationsResponse) {}
}
機能の詳細な説明
このセクションでは、HM のさまざまな側面について詳しく説明します。
生存ハートビートのモニタリング
サービス バンドル インスタンスに生存監視が構成されている場合、HM は、インスタンスが定期的にハートビートをパブリッシュして、ビジネス ロジックが正しく動作していることを証明することを想定しています。このモニタリングは、定期的なタスクを実行するサービス バンドル インスタンスに最適です。また、非同期ランタイムを使用するバンドルは、生存モニタリングを使用して、スレッドプールが枯渇していないことを証明できます。
図 1. HM の生存モニタリング フロー。
構成
サービス バンドル インスタンスでアライブネス HB を有効にするには、バンドル構成の health_config フィールドに HealthConfiguration のインスタンスを追加します。
アライブネス ハートビート構成は、サービスの定期的なハートビート信号を評価する基準を確立する、事前に定義されたパラメータのセットを定義します。サービス ハートビートの特性がこれらのパラメータから逸脱している場合、ハートビートは遅延として分類され、対応するサービス バンドルは異常として分類されます。これは、最適な運用状態ではないことを示している可能性があります。
サービス バンドルは、ヘルス構成に従ってハートビートを時間どおりに報告すると、正常とみなされます。クラッシュやシステム負荷が高い場合、ハートビートが欠落したり遅延したりして、サービス バンドルが異常としてマークされることがあります。この場合、違反は VmHealth レポートに表示されます。
サービス バンドルのデベロッパーは、対応する APEX メタデータでサービス バンドルのヘルス構成を定義する必要があります。ヘルス構成では、次の条件を定義します。
サービスの開始から最初のハートビート検出までの最大初期遅延。
SDV サービス バンドルがビジネス ロジックを実行する期間。これは、サービス ハートビートをパブリッシュする周期に対応します。
HM がサービス バンドルを異常とみなすまでに、欠落する期間の数。
実行時間とは、SDV サービス バンドルがサービス ハートビートを公開する前にビジネス ロジックを実行するために必要な時間です。
サービス バンドルは、サービスのハートビートが遅延すると、健全性違反を生成します。健康状態の観察時間に基づいて、次の 2 つのケースがあります。
ケース 1: 最初のハートビートが受信されなかった。サービス バンドルの開始からモニタリングまでの間に、許可された初期遅延を超えた場合、サービス バンドルは異常と見なされます。
ケース 2: ハートビートがすでに受信されている。最後のハートビートとモニタリングの時間の間にしきい値が経過すると、サービス バンドルは異常と見なされます。このしきい値は、レポート対象期間(期間数を乗算)とタスクの期間の合計として計算されます。
ヘルス構成の形式は //system/software_defined_vehicle/health_monitor/catalog/health_config.proto で定義されています。
package com.android.sdv.health;
// Service Bundle's configuration for health monitoring.
message HealthConfiguration {
// Required.
// Initial delay in milliseconds is the time between the service starts and its first heartbeat.
optional uint64 initial_delay_ms = 2;
// Required.
// Period of reporting a heartbeat in milliseconds which corresponds to the periodicity of
// executing a business logic by the SDV service. This value should be larger than 0.
optional uint64 period_ms = 3;
// Required.
// The number of periods missing a heartbeat before the Health Monitor should consider the
// service as unhealthy. This value should be larger than 0.
optional uint64 num_periods = 4;
// Required.
// Duration of the business logic the SDV service bundle executes in milliseconds.
optional uint64 task_duration_ms = 5;
}
実行時間に関する考慮事項
このセクションでは、生存ハートビートをパブリッシュし、モニタリングに正しく登録するためのガイダンスを提供します。
生存ハートビートを公開する
サービス バンドル インスタンスは、タイムスタンプを含むサービス ハートビート メッセージを生成します。通常は、メインのビジネス ロジックが実行された直後に、メッセージを定期的に生成します。サービス ハートビートは、サービス バンドルがアクティブであることを示します。
モニタリング対象のバンドル インスタンス オブジェクトは、ServiceHeartbeat タイプのパブリッシャーを作成する必要があります。これは libhealth_api ライブラリで利用できます。
message ServiceHeartbeat {
// Required.
// The timestamp.
.google.protobuf.Timestamp timestamp = 1;
}
パブリケーション トピックを任意に選択します。HM エージェントは、メッセージ タイプによる検出を使用してパブリケーションを検出します。
対応するサービス バンドル マニフェストにリンクされているヘルス構成を介して生存モニタリングを構成する場合、HM エージェントは、インスタンスが on_start ルーティンを完了するとすぐに HB が公開されることを想定しています。システムの起動をブロックしないように、on_start は短くすることをおすすめします。そのため、on_start で開始された非同期タスクでハートビートをパブリッシュします。
バンドル デベロッパーは、initial_delay_ms 構成エントリを使用して、最初のハートビートが想定される時間をカスタマイズできます。
バンドル インスタンスは、停止するまでハートビートをパブリッシュし続ける必要があります。on_stop ルーティンが終了すると、インスタンスは停止したと見なされます。
特殊なユースケース: ハートビート モニタリングに明示的に登録する
生存ハートビート モニタリングで説明されている、on_start と on_stop の間でハートビートが想定される動作は、暗黙的な生存モニタリングと呼ばれます。これは、この機能を使用する際におすすめの方法です。バンドルのビジネス ロジックが簡素化され、バンドルが常にモニタリングされるようになります。
ただし、デフォルトのモニタリング期間が制限となるユースケースもあります。
- サービス バンドル インスタンスには、
startイベントとstopイベントにリンクされていない時間間隔で定期的に実行されるビジネス ロジックが含まれています。このカスタム期間にのみ、生存モニタリングが必要になる場合があります。 - HM は、一時停止期間と再開期間にわたって HB を正確に追跡します。そのため、バンドルは
on_stop後もモニタリングを継続することが望ましい場合があります。 - カスタム OEM エージェントは、サービス バンドルとして実装されていない場合があります。したがって、暗黙的な稼働状況モニタリングのメリットを享受できません。ただし、生存モニタリングが必要になる場合があります。
このような場合、HM では、明示的な登録を優先して、生存監視への暗黙的な登録をバイパスできます。明示的な登録を使用するには、バンドルのマニフェストに特定のインスタンスの HealthConfiguration 種類のエントリを含めないことで、バンドル インスタンスが暗黙的な登録をオプトアウトする必要があります。次に、実行時に、バンドル インスタンスは //system/software_defined_vehicle/health_monitor/catalog/health_monitor_registration_service.proto で定義された RPC API を使用して、モニタリングから手動で登録および登録解除する必要があります。登録 RPC 呼び出しが成功するとすぐに、公開されたハートビートが想定されます。
実装例については、//system/software_defined_vehicle/samples/health/stable/health_monitored_service_bundle/ をご覧ください。
QoS モニタリング
Quality of Service(QoS)は、通信の測定値です。HM は、送信されたメッセージが転送中に過剰な時間を費やしているかどうか、または定期的な通信の場合、選択した頻度でメッセージが受信されていないかどうかをモニタリングします。
SDV には、Pub/Sub 通信と RPC 通信のいくつかの種類が用意されています。共通点は、すべての通信スキームに少なくとも 1 つのリスナーが含まれていることです。HM が通信をモニタリングするには、このリスニング サービス バンドル インスタンスは、対象のメッセージを受信するたびに特別な QoS ハートビートをパブリッシュする必要があります。
構成
通信の QoS モニタリングを有効にするには、まず、QoS ハートビートをパブリッシュする通信リスナーを特定します。次に、特定されたサービス バンドル インスタンスについて、qos_config フィールドの QosMonitoringConfiguration マッピングに 1 つ以上のトピックを追加します。詳細については、サービスごとのバンドル構成をご覧ください。
topic は、HM が実行時に QoS HB を想定するパブリケーション トピックを定義する文字列です。リスニング バンドル インスタンスは、複数の通信に参加し、複数のトピックで QoS HB を報告できます。
実行時に QoS 違反が検出されると、トピックは HM リスナー サービス バンドルに報告されるため、トピックはわかりやすいものにする必要があります。
QosMonitoringConfiguration 型は //system/software_defined_vehicle/health_monitor/catalog/health_config.proto で定義されています。
message QosMonitoringConfiguration {
// Optional - If absent, heartbeat frequency monitoring is disabled for this SB.
//
// The maximum allowable interval between consecutive heartbeats (in milliseconds).
// A QoS frequency violation is triggered if the time elapsed between
// two heartbeats exceeds this threshold.
optional uint64 qos_period_threshold_ms = 1;
// Optional - If absent, heartbeat latency monitoring is disabled for this SB.
//
// The maximum allowable interval between data publication and data processing timestamps (in milliseconds).
// A QoS latency violation is triggered if the time elapsed between
// data publication and data processing timestamps exceeds this threshold.
optional uint64 qos_latency_threshold_ms = 2;
}
デフォルトのユースケースでは、両方のタイプの QoS モニタリングを適用します。通常のシステム負荷での VM 内 Pub/Sub 通信には、30 の qos_latency_threshold_ms が妥当です。
実行時間に関する考慮事項
生存 HB モニタリングと同様に、通信リスニング バンドルは、ある種のハートビートをパブリッシュすることが想定されています。この場合、QoS HB は、ビジネス ロジックの実行終了時ではなく、対象のメッセージが受信されるたびに公開する必要があります。
QoS HB は QosHeartbeat 型で、//system/software_defined_vehicle/health_monitor/catalog/qos_heartbeat.proto で定義されています。
message QosHeartbeat {
option (.sdv.vsidl.v1.publication) = {
message_count: 2
model: SINGLE_PUB
};
// Required.
// Current timestamp at heartbeat transmission. The heartbeat should be sent
// immediately after the listener receives the related QoS-monitored message.
.google.protobuf.Timestamp timestamp = 1;
// Required.
// Timestamp corresponding to the creation time of the underlying data. This
// implies that, in addition to the data of interest, the monitored message includes
// a data creation timestamp field. The listener is responsible for routing this
// timestamp to the QosHeartbeat upon receiving a QoS-monitored message.
.google.protobuf.Timestamp data_timestamp = 2;
}
QoS HB パブリケーションの登録と登録解除のタイミングは、正確なモニタリングに不可欠です。HM は、これら 2 つのイベントの間に QoS HB を想定しています。メッセージ リスニング バンドルは、モニタリング対象の通信が SDV 通信スタックに登録されたときに、QoS HB パブリケーションを登録する必要があります。HM は、空き状況 API を使用してこれを行うことができます。詳細については、サービスの提供状況を確認するをご覧ください。
サービス バンドルの復元モニタリング
サービス バンドル インスタンスの復元は、オーケストレーター エージェントの構成ファイルの一部として構成されます。このトピックの詳細については、サービス バンドルをご覧ください。HM サブシステムは、復元プロセスを受動的に監視します。バンドル インスタンスの復元に失敗したことが検出されると、VMHealth レポートに違反が追加されます。他の HM モニタリング機能とは異なり、復元モニタリングは必須であり、構成できません。
復元用に構成されていないサービス バンドル インスタンスがクラッシュすると、最初のクラッシュでヘルス違反が生成されます。
サービス バンドル インスタンスの復元は、ハートビートの稼働状況モニタリングと統合するように設計されています。HM システムは、バンドルが回復していることを検出すると、ハートビートの評価をより緩やかにします。実際には、この寛容さにより、サービス バンドルがクラッシュした場合に、追加のモニタリングの登録解除や登録の手順を行う必要がありません。
エージェントのクラッシュのモニタリング
HM は、バインダー linkToDeath メカニズムを使用して、SDV エージェントの潜在的なクラッシュを検出します。
クラッシュ モニタリングは、VM の健全性構成(SDV インスタンス(VM)ごとの構成を参照)の一部として、具体的には monitored_agent 繰り返しフィールドで構成できます。このフィールドには、BinderServiceAgent 型のエントリを含める必要があります。
message BinderServiceAgent {
// agent_names must be unique across configuration
// used for HM internal agent identification, and naming entries in HM dumpsys report
string agent_name = 1;
// Binder interface name/identifier, e.g: "google.sdv.data_tunnel.IAgentService/default"
// HM Agent should have appropriate permissions to find the binder interface
// see also `sdv_crash_monitored_service` selinux attribute
string binder_interface_name = 2;
}
エージェントがバインダー インターフェースを公開している場合は、カスタム エージェントをモニタリングすることもできます。カスタム エージェントをモニタリングするには、適切なバインダー インターフェースをリッスンする HM SELinux 権限を付与します。
システム プロパティ ro.boot.sdv.health_monitor.agent_startup_timeout_sec を使用すると、HM が起動してからエージェントがバインダー インターフェースを登録するまでの HM の待機時間をオーバーライドできます。カスタム エージェントで必要とされない限り、デフォルトの 3 秒が適切です。
サービス バンドル デベロッパー ガイド
このセクションでは、前のセクションの理論的な説明とは対照的に、サービス バンドルの HM 機能を使用する方法について、手順ガイドを説明します。これらのガイドのベースとなっている最新の参照サンプルは、qos_monitoring サンプルです。サンプルの //system/software_defined_vehicle/samples/health/stable/qos_monitoring/README に沿って、実践的な演習を行います。
サービス バンドルに生存ハートビート モニタリングを追加する
この方法は、サービス バンドルのヘルス モニタリングを有効にする最も直接的な方法です。
health_configuration.textprotoという名前のファイルで、バンドル インスタンスのServiceBundleHealthConfigurationのインスタンスを定義します。# health_bundle_configuration.textproto instance_config { key: "instance1" value: { health_config { initial_delay_ms: 1000 period_ms: 500 num_periods: 2 task_duration_ms: 200 } # qos_config entries irrelevant for this dev guide qos_config { ... } } }構成ファイルをサービス バンドル APEX に追加します。
Android.bpの場合:apex { name: "com.android.sdv.sample.oem.health.qos_monitoring", // ... prebuilts: [ // ... "com.android.sdv.sample.oem.health.qos_monitoring.health_config", ], } prebuilt_etc { name: "com.android.sdv.sample.oem.health.qos_monitoring.health_config", src: "health_configuration.textproto", filename: "health.textproto", // ... // Reduce prebuilt visibility to avoid adding it in another APEX. visibility: ["//system/software_defined_vehicle/samples/health/qos_monitoring/apex"], }ヘルス構成を APEX に保存し、マニフェストで
health_config_pathを設定します。# sdv_service_bundles_manifest.textproto sdv_service_bundle_metadata { ... health_config_path: "etc/config/health_configuration.textproto" }VSIDL 定義で、バンドルが
com.android.sdv.health.ServiceHeartbeatを公開していることを確認します。sdv_service_bundle { name: "SampleBundle" publisher { message: "com.android.sdv.health.ServiceHeartbeat" topic: "arbitrary-topic" capacity: 2 } }バンドルに SDV 権限を追加して、バンドルが HB を公開できるようにします。
publisher { type: "com.android.sdv.health.ServiceHeartbeat" }on_start以降、コードでサービス ハートビートを定期的に公開します。// ... fn on_start(&mut self) { // ... runtime.spawn(business_logic(self.context)) } async fn business_logic(context: ContextRef) -> SdvResult<()>{ // register HB publication let mw_comms = SdvComms { context }; let aliveness_hb_pub = create_publisher::<PublisherDescriptor<ServiceHeartbeat>>( &mw_comms, PublisherDescriptors::<ServiceHeartbeat>::ARBITRARY_TOPIC, ) .await?; loop{ // do business logic // ... // publish hb aliveness_hb_pub.publish(&ServiceHeartbeat { timestamp: MessageField(Some(Box::new(now.into()))), ..Default::default() })?; } }
特殊なユースケース: 明示的な登録
バンドルでカスタム ライフサイクルの HB モニタリングが必要な、より特殊なユースケース(標準の STARTED 状態よりも早く開始または遅く終了するモニタリングなど)では、明示的な登録方法を使用できます。
VSIDL 定義に
com.android.sdv.health.HealthMonitorRegistrationServiceクライアントを追加します。sdv_service_bundle { # ... client { service: "com.android.sdv.health.HealthMonitorRegistrationService" channel: "com-android-sdv-health-health-monitor-registration-service" } }aliveness HB 登録 RPC を使用するための SDV 権限を追加します。
# ... client { service: "com.android.sdv.health.HealthMonitorRegistrationService" channel: "com-android-sdv-health-health-monitor-registration-service" }RPC を介して HM に登録します(例:
on_startまたはnew)。let rpc_client = Self::new_client(comms).await?; let _ = rpc_client .RegisterConfiguration(&RegisterConfigurationRequest { config: Some(HealthConfiguration{ initial_delay_ms: 100, period_ms: 200, num_periods: 3, task_duration_ms: 40, special_fields: protobuf::SpecialFields::default(), }).into(), ..Default::default() }) .await .unwrap();HB を公開します。
不要になったらモニタリングの登録を解除する
let _ = rpc_client .UnregisterConfiguration(&UnregisterConfigurationRequest { ..Default::default() }) .await .unwrap();
通信に QoS モニタリングを追加する
サービス バンドル インスタンスが、VSIDL カタログの
fog-light-statusという名前のトピックのサブスクライバーであることを確認します。subscriber { message: "QosMonitoredFogLightStatus" topic: "left-fog-light-status" }メッセージの形式は次のとおりです。
package com.android.sdv.sample.oem.health.qos_monitoring; import "google/protobuf/timestamp.proto"; message QosMonitoredFogLightStatus { // arbitrary fields related to business logic int32 status = 1; // A QoS-monitored message must include a timestamp field .google.protobuf.Timestamp timestamp = 2; }QoS モニタリングを含む
health_configuration.textprotoファイルで、バンドル インスタンスのServiceBundleHealthConfigurationのインスタンスを定義します。# health_bundle_configuration.textproto instance_config { key: "instance1" value: { # aliveness HB monitoring config irrelevant for this dev guide health_config { ... } qos_config { key: "qos-hb-right-fog-light-status" value { qos_period_threshold_ms: 100 qos_latency_threshold_ms: 50 } } } }keyフィールドで選択したトピックは、QoS HB がこのトピックで公開され、fog-light-statusというトピックをモニタリングできることを示しています。構成ファイルをサービス バンドル APEX に追加します。
Android.bpの場合:apex { name: "com.android.sdv.sample.oem.health.qos_monitoring", // ... prebuilts: [ // ... "com.android.sdv.sample.oem.health.qos_monitoring.health_config", ], } prebuilt_etc { name: "com.android.sdv.sample.oem.health.qos_monitoring.health_config", src: "health_configuration.textproto", filename: "health.textproto", // ... // Reduce prebuilt visibility to avoid adding it in another APEX. visibility: ["//system/software_defined_vehicle/samples/health/qos_monitoring/apex"], }ヘルス構成を APEX に保存し、マニフェストで
health_config_pathを設定します。# sdv_service_bundles_manifest.textproto sdv_service_bundle_metadata { ... health_config_path: "etc/config/health_configuration.textproto" }VSIDL 定義で、バンドルが
com.android.sdv.health.QosHeartbeatのパブリッシャーであることを確認します。sdv_service_bundle { name: "SampleBundle" publisher { message: "com.android.sdv.health.QosHeartbeat" topic: "qos-hb-right-fog-light-status" capacity: 2 } }バンドルに SDV 権限を追加して、バンドルが QoS HB を公開できるようにします。
publisher { message: "com.android.sdv.health.QosHeartbeat" topic: "qos-hb-right-fog-light-status" }QoS HB パブリケーションは、モニタリング対象の通信が登録されている場合にのみ登録します。
libsdv_mw_clientlibの Availability API を使用します。// Wait for monitored communication to be available let comms = SdvComms{context}; let registration_stream = create_registration_event_stream( &comms, SubscriberDescriptors::<QosMonitoredFogLightStatus>::LEFT_FOG_LIGHT_STATUS, ).await?; let mut registration_stream = Box::pin(registration_stream.filter(|e|e==Availability::Available)); registration_stream.next().await; // only when available, create QoS HB publication: let qos_hb_pub = create_publisher( &comms, PublisherDescriptors::<QosHeartbeat>::QOS_HB_LEFT_FOG_LIGHT_STATUS, ).await?; // ...メッセージを受信するたびに QoS HB をパブリッシュします。
// ... use tap::Pipe; fn flatten_mw<T: Send>( s: impl Stream<Item = SdvResult<Vec<T>>> + Send + Unpin, ) -> impl Stream<Item = SdvResult<T>> + Send + Unpin { s.flat_map(|v| match v { Ok(v) => v.into_iter().map(Ok).pipe(stream::iter).left_stream(), Err(err) => Err(err).pipe(future::ready).pipe(stream::once).right_stream(), }) } { // ... let data_stream = create_observer( &comms, SubscriberDescriptors::<QosMonitoredFogLightStatus>::LEFT_FOG_LIGHT_STATUS, SubscribeOptions::default() ) .pipe(flatten_mw) .await?; while let Some(data) = data_stream.next().await { // publish QoS HB. Note how data.timestamp is used to populate the field qos_hb_pub.publish( &QosHeartbeat { timestamp: SystemTime::now(), data_timestamp: data.timestamp, ..Default::default() } ) // use data // ... } }QoS モニタリングを停止するには、パブリッシャー オブジェクトを削除します。
// ... drop(qos_hb_pub);
ヘルス モニタリングをデバッグする
デバッグとシステム概要の目的で、dumpsys ツールを使用して VM のヘルス モニタリングの状態をモニタリングします。
adb shell dumpsys com.google.sdv.ISdvAgent/hm
このレポートには、VM の稼働状況レポートの構成、バンドル構成、モニタリング状態の詳細が記載されています。このようなレポートの例を次に示します。
AGENT NAME: SDV Agent dump - Health Monitor
AGENT FQIN: instance1:com.android.sdv.health.HealthMonitorServiceBundle/instance1
AGENT STATE: Started
----------------
----------------
INTERNAL STATE REPORTERS:
*NAME: VM health report period:
*REPORT:
100----------------
*NAME: Recovery monitor manager
*REPORT:
HEARTBEAT MONITORING:
NO ACTIVE MONITORS
QOS MONITORING:
NO ACTIVE MONITORS
RECOVERY MONITORING:
a. Agent monitoring:
MONITOR 0:
ID: Agent: sdv_vsidl_provider_agent
linked_binder: com.google.sdv.ISdvAgent/vsidl_provider
alive: true
MONITOR 1:
ID: Agent: sdv_someip_broker
linked_binder: com.google.sdv.ISdvAgent/someip_broker
alive: false
b. SB monitoring:
MONITOR 0:
ID: FQIN: instance1:com.android.sdv.test.orchestrator.OrchSampleInitialPowerState/sample-initial-power-state
Recovery State: Normal
Lifecycle State: Started
Health Status: Healthy
MONITOR 1:
ID: FQIN: instance1:com.android.sdv.sample.apex.provider.Provider/sample-provider-v1
Recovery State: Normal
Lifecycle State: Started
Health Status: Healthy
MONITOR 2:
ID: FQIN: instance1:com.sdv.google.display_safety.HarSdvVehicleDataPublisher/instance-1
Recovery State: Normal
Lifecycle State: Started
Health Status: Healthy
----------------
*NAME: Health monitor
*REPORT:
CURR TIMESTAMP(ns): 1775543863756836167
INTERNAL STATE:
background_thread running: true
should_run: true
----------------