健康狀態檢查是標準化檢查指標。新增 fuchsia.inspect.Health 孩子
提供給該節點的健康資訊。這類資訊
會由整個系統的健康狀態檢查工具匯總
健康狀態檢查節點的配置
下列資源和指標匯出至任何健康狀態檢查節點:
| 名稱 | 類型 | 說明 | 
|---|---|---|
| start_timestamp_nanos | int64 | 這個健康狀態節點初始化時的單調時鐘系統時間戳記 (即首次變為 STARTING UP) | 
| message | 字串 | 如果為 status==UNHEALTHY,則訊息會包含選擇性的失敗詳細資料訊息。 | 
| status | 列舉 | STARTING_UP:健康狀態節點已初始化,但尚未標示為執行中。 | 
| OK:向這個健康狀態節點回報的子系統回報健康狀態良好。 | ||
| UNHEALTHY:向這個健康狀態節點回報的子系統回報健康狀態不良。 | 
使用手冊
下例說明如何使用 ffx inspect 取得
以及元件健康狀態
例如:
$ ffx inspect show
core/a:
  root:
    fuchsia.inspect.Health:
      start_timestamp_nanos = ...
      status = OK
    connections:
      0:
        fuchsia.inspect.Health:
          start_timestamp_nanos = ...
          status = STARTING_UP
    optional_database:
      fuchsia.inspect.Health:
        start_timestamp_nanos = ...
        status = UNHEALTHY
        message = "Cannot open local.file"
core/a:
  root:
    fuchsia.inspect.Health:
      start_timestamp_nanos = ...
      status = OK
core/a:
  root:
    fuchsia.inspect.Health:
      start_timestamp_nanos = ...
      status = UNHEALTHY
      message = "Failed to connect to fuchsia.example.RequiredService"
$ ffx inspect show a.cm:root/fuchsia.inspect.Health:status b.cm:root/fuchsia.inspect.Healh:status c.cm:root/fuchsia.inspect.Health:status
a:
  root:
    fuchsia.inspectHealth:
      status = OK
b:
  root:
    fuchsia.inspectHealth:
      status = OK
c:
  root:
    fuchsia.inspectHealth:
      status = UNHEALTHY
在元件中使用健康狀態檢查
以下各節說明如何使用以下列語言編寫的 Fuchsia 元件中的程式庫 提供多種程式設計語言
C++
  #include <lib/async-loop/cpp/loop.h>
  #include <lib/async-loop/default.h>
  #include <lib/sys/cpp/component_context.h>
  #include <lib/inspect/component/cpp/component.h>
  int main(int argc, char** argv) {
    async::Loop loop(&kAsyncLoopConfigAttachToCurrentThread);
    auto context = sys::ComponentContext::CreateAndServeOutgoingDirectory();
    inspect::ComponentInspector inspector(loop.dispatcher(), inspect::PublishOptions{});
    inspector.Health().StartingUp();
    // ...Do startup work...
    inspector.Health().Ok();
    inspector.Health().Unhealthy("I'm not feeling well.");
    inspector.Health().Ok();
    loop.Run();
    return 0;
  }
荒漠油廠
  use fuchsia_inspect as inspect;
  use fuchsia_inspect::health;
  fn main() {
    // If you have your own inspector, it's also possible to export its health.
    /* inspector needs to be initialized */
    let inspector = /* ... */
    let mut node = inspector::root();
    let mut health = fuchsia_inspect::health::Node(node);
    // ...
    health.set_ok();
    health.set_unhealthy("I'm not feeling well.");
    health.set_ok();  // The component is healthy again.
  }