健康狀態檢查是標準化的檢查指標。將 fuchsia.inspect.Health
子項新增至 Inspect Node,可為該節點提供包含的健康資訊。這項資訊可以由整個系統的健康狀態檢查工具匯總。
健康狀態檢查節點的版面配置
下列屬性和指標會匯出至任何健康狀態檢查節點:
名稱 | 類型 | 說明 |
---|---|---|
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;
}
Rust
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.
}