健康检查是一项标准化的检查指标。添加一个 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.
}