health_report/
health_report.rs1use std::{error::Error, time::Duration};
2
3use beatwise::{HealthPolicy, Monitor, TaskConfig, Timing};
4
5fn main() -> Result<(), Box<dyn Error>> {
6 let monitor = Monitor::new();
7 let heartbeat = monitor.register(TaskConfig::new(
8 "api-worker",
9 Timing::fixed(Duration::from_secs(1)),
10 ))?;
11
12 let starting = monitor.summary(HealthPolicy::readiness());
13 println!(
14 "before first beat: verdict={:?}, starting={}",
15 starting.verdict, starting.counts.starting,
16 );
17
18 heartbeat.beat()?;
19
20 let report = monitor.report(HealthPolicy::liveness());
21 println!(
22 "after first beat: verdict={:?}, healthy={}",
23 report.summary.verdict, report.summary.counts.healthy,
24 );
25 for task in report.tasks.iter() {
26 println!("{}: {:?}", task.name, task.health);
27 }
28
29 Ok(())
30}