pub struct HealthCheck { /* private fields */ }Implementations§
Source§impl HealthCheck
impl HealthCheck
pub fn new() -> Self
Sourcepub fn is_heartbeat_recent(&self, threshold: Duration) -> bool
pub fn is_heartbeat_recent(&self, threshold: Duration) -> bool
Check if heartbeat is recent (within threshold)
Sourcepub fn add_check(
&self,
name: impl Into<String>,
status: HealthStatus,
message: impl Into<String>,
)
pub fn add_check( &self, name: impl Into<String>, status: HealthStatus, message: impl Into<String>, )
Add a custom health check
Examples found in repository?
examples/industry40_health.rs (lines 56-60)
4fn main() {
5 let scaling_config = ScalingConfig {
6 min_threads: 2,
7 max_threads: 8,
8 target_queue_length: 50,
9 scale_up_threshold: 0.7,
10 scale_down_threshold: 0.3,
11 cooldown_period: Duration::from_secs(2),
12 };
13
14 let config = RuntimeConfig {
15 num_threads: Some(4),
16 enable_autoscaling: true,
17 scaling_config,
18 ..Default::default()
19 };
20
21 let rt = Runtime::with_config(config);
22
23 println!("🏥 Health Monitoring System - Industry 4.0");
24 println!("=========================================\n");
25
26 rt.block_on(async move {
27 // Simulate various workload conditions
28 println!("📊 Phase 1: Normal Operation");
29 println!("---------------------------");
30
31 for i in 0..10 {
32 rt.spawn(async move {
33 avx_async::sleep(Duration::from_millis(100)).await;
34 });
35 }
36
37 avx_async::sleep(Duration::from_millis(500)).await;
38 print_health_status(&rt);
39
40 println!("\n📊 Phase 2: High Load");
41 println!("--------------------");
42
43 for i in 0..50 {
44 rt.spawn(async move {
45 avx_async::sleep(Duration::from_millis(200)).await;
46 });
47 }
48
49 avx_async::sleep(Duration::from_millis(300)).await;
50 print_health_status(&rt);
51
52 // Simulate a degraded state
53 println!("\n⚠️ Phase 3: Degraded Service");
54 println!("---------------------------");
55
56 rt.health().add_check(
57 "database_connection",
58 HealthStatus::Degraded,
59 "Connection pool at 85% capacity"
60 );
61
62 rt.health().add_check(
63 "cache_latency",
64 HealthStatus::Degraded,
65 "Cache response time > 100ms"
66 );
67
68 print_health_status(&rt);
69
70 // Simulate recovery
71 println!("\n✅ Phase 4: Recovery");
72 println!("------------------");
73
74 rt.health().clear_checks();
75
76 // Wait for queue to drain
77 while rt.task_count() > 0 {
78 avx_async::sleep(Duration::from_millis(100)).await;
79 }
80
81 print_health_status(&rt);
82
83 println!("\n📤 Health Check JSON Export");
84 println!("==========================");
85 let report = rt.health().get_report();
86 println!("{}", report.to_json());
87 });
88}Sourcepub fn get_status(&self) -> HealthStatus
pub fn get_status(&self) -> HealthStatus
Get overall health status
Sourcepub fn get_report(&self) -> HealthReport
pub fn get_report(&self) -> HealthReport
Get detailed health report
Examples found in repository?
examples/industry40_metrics.rs (line 31)
4fn main() {
5 // Create runtime with Industry 4.0 features
6 let config = RuntimeConfig {
7 num_threads: Some(4),
8 enable_autoscaling: false,
9 ..Default::default()
10 };
11
12 let rt = Runtime::with_config(config);
13
14 println!("🏭 Industry 4.0 Metrics Dashboard");
15 println!("================================\n");
16
17 rt.block_on(async move {
18 // Spawn multiple tasks to generate metrics
19 for i in 0..20 {
20 rt.spawn(async move {
21 avx_async::sleep(Duration::from_millis(50 * (i % 5) as u64)).await;
22 // Simulate work
23 });
24 }
25
26 // Monitor metrics in real-time
27 for iteration in 0..5 {
28 avx_async::sleep(Duration::from_millis(200)).await;
29
30 let snapshot = rt.metrics().snapshot();
31 let health = rt.health().get_report();
32
33 println!("📊 Iteration {}", iteration + 1);
34 println!(" {}", snapshot);
35 println!(" Health: {} | Ready: {} | Alive: {}",
36 health.status, health.ready, health.alive);
37 println!();
38 }
39
40 // Wait for all tasks to complete
41 while rt.task_count() > 0 {
42 avx_async::sleep(Duration::from_millis(50)).await;
43 }
44
45 println!("📈 Final Metrics Report");
46 println!("=====================");
47 let final_snapshot = rt.metrics().snapshot();
48 println!("{}", final_snapshot);
49 println!();
50
51 println!("🏥 Health Check Report");
52 println!("====================");
53 let health_report = rt.health().get_report();
54 println!("{}", health_report);
55 println!();
56
57 println!("📤 Prometheus Export");
58 println!("===================");
59 println!("{}", rt.metrics().to_prometheus());
60 });
61}More examples
examples/industry40_health.rs (line 85)
4fn main() {
5 let scaling_config = ScalingConfig {
6 min_threads: 2,
7 max_threads: 8,
8 target_queue_length: 50,
9 scale_up_threshold: 0.7,
10 scale_down_threshold: 0.3,
11 cooldown_period: Duration::from_secs(2),
12 };
13
14 let config = RuntimeConfig {
15 num_threads: Some(4),
16 enable_autoscaling: true,
17 scaling_config,
18 ..Default::default()
19 };
20
21 let rt = Runtime::with_config(config);
22
23 println!("🏥 Health Monitoring System - Industry 4.0");
24 println!("=========================================\n");
25
26 rt.block_on(async move {
27 // Simulate various workload conditions
28 println!("📊 Phase 1: Normal Operation");
29 println!("---------------------------");
30
31 for i in 0..10 {
32 rt.spawn(async move {
33 avx_async::sleep(Duration::from_millis(100)).await;
34 });
35 }
36
37 avx_async::sleep(Duration::from_millis(500)).await;
38 print_health_status(&rt);
39
40 println!("\n📊 Phase 2: High Load");
41 println!("--------------------");
42
43 for i in 0..50 {
44 rt.spawn(async move {
45 avx_async::sleep(Duration::from_millis(200)).await;
46 });
47 }
48
49 avx_async::sleep(Duration::from_millis(300)).await;
50 print_health_status(&rt);
51
52 // Simulate a degraded state
53 println!("\n⚠️ Phase 3: Degraded Service");
54 println!("---------------------------");
55
56 rt.health().add_check(
57 "database_connection",
58 HealthStatus::Degraded,
59 "Connection pool at 85% capacity"
60 );
61
62 rt.health().add_check(
63 "cache_latency",
64 HealthStatus::Degraded,
65 "Cache response time > 100ms"
66 );
67
68 print_health_status(&rt);
69
70 // Simulate recovery
71 println!("\n✅ Phase 4: Recovery");
72 println!("------------------");
73
74 rt.health().clear_checks();
75
76 // Wait for queue to drain
77 while rt.task_count() > 0 {
78 avx_async::sleep(Duration::from_millis(100)).await;
79 }
80
81 print_health_status(&rt);
82
83 println!("\n📤 Health Check JSON Export");
84 println!("==========================");
85 let report = rt.health().get_report();
86 println!("{}", report.to_json());
87 });
88}
89
90fn print_health_status(rt: &Runtime) {
91 let metrics = rt.metrics().snapshot();
92 let health = rt.health().get_report();
93
94 println!("Status: {} | Ready: {} | Alive: {}",
95 health.status, health.ready, health.alive);
96 println!("Tasks: {} active | Queue: {} items",
97 metrics.tasks_spawned - metrics.tasks_completed,
98 metrics.queue_length);
99 println!("Threads: {} active, {} idle",
100 metrics.active_threads, metrics.idle_threads);
101
102 if !health.checks.is_empty() {
103 println!("Health Checks:");
104 for check in &health.checks {
105 println!(" - {} [{}]: {}", check.name, check.status, check.message);
106 }
107 }
108}Sourcepub fn clear_checks(&self)
pub fn clear_checks(&self)
Clear all checks
Examples found in repository?
examples/industry40_health.rs (line 74)
4fn main() {
5 let scaling_config = ScalingConfig {
6 min_threads: 2,
7 max_threads: 8,
8 target_queue_length: 50,
9 scale_up_threshold: 0.7,
10 scale_down_threshold: 0.3,
11 cooldown_period: Duration::from_secs(2),
12 };
13
14 let config = RuntimeConfig {
15 num_threads: Some(4),
16 enable_autoscaling: true,
17 scaling_config,
18 ..Default::default()
19 };
20
21 let rt = Runtime::with_config(config);
22
23 println!("🏥 Health Monitoring System - Industry 4.0");
24 println!("=========================================\n");
25
26 rt.block_on(async move {
27 // Simulate various workload conditions
28 println!("📊 Phase 1: Normal Operation");
29 println!("---------------------------");
30
31 for i in 0..10 {
32 rt.spawn(async move {
33 avx_async::sleep(Duration::from_millis(100)).await;
34 });
35 }
36
37 avx_async::sleep(Duration::from_millis(500)).await;
38 print_health_status(&rt);
39
40 println!("\n📊 Phase 2: High Load");
41 println!("--------------------");
42
43 for i in 0..50 {
44 rt.spawn(async move {
45 avx_async::sleep(Duration::from_millis(200)).await;
46 });
47 }
48
49 avx_async::sleep(Duration::from_millis(300)).await;
50 print_health_status(&rt);
51
52 // Simulate a degraded state
53 println!("\n⚠️ Phase 3: Degraded Service");
54 println!("---------------------------");
55
56 rt.health().add_check(
57 "database_connection",
58 HealthStatus::Degraded,
59 "Connection pool at 85% capacity"
60 );
61
62 rt.health().add_check(
63 "cache_latency",
64 HealthStatus::Degraded,
65 "Cache response time > 100ms"
66 );
67
68 print_health_status(&rt);
69
70 // Simulate recovery
71 println!("\n✅ Phase 4: Recovery");
72 println!("------------------");
73
74 rt.health().clear_checks();
75
76 // Wait for queue to drain
77 while rt.task_count() > 0 {
78 avx_async::sleep(Duration::from_millis(100)).await;
79 }
80
81 print_health_status(&rt);
82
83 println!("\n📤 Health Check JSON Export");
84 println!("==========================");
85 let report = rt.health().get_report();
86 println!("{}", report.to_json());
87 });
88}Trait Implementations§
Source§impl Clone for HealthCheck
impl Clone for HealthCheck
Auto Trait Implementations§
impl Freeze for HealthCheck
impl RefUnwindSafe for HealthCheck
impl Send for HealthCheck
impl Sync for HealthCheck
impl Unpin for HealthCheck
impl UnwindSafe for HealthCheck
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)