HealthCheck

Struct HealthCheck 

Source
pub struct HealthCheck { /* private fields */ }

Implementations§

Source§

impl HealthCheck

Source

pub fn new() -> Self

Source

pub fn set_ready(&self, ready: bool)

Set readiness status (can accept new work)

Source

pub fn is_ready(&self) -> bool

Check if runtime is ready

Source

pub fn set_alive(&self, alive: bool)

Set liveness status (runtime is functioning)

Source

pub fn is_alive(&self) -> bool

Check if runtime is alive

Source

pub fn heartbeat(&self)

Update heartbeat timestamp

Source

pub fn is_heartbeat_recent(&self, threshold: Duration) -> bool

Check if heartbeat is recent (within threshold)

Source

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}
Source

pub fn get_status(&self) -> HealthStatus

Get overall health status

Source

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
Hide additional 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}
Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for HealthCheck

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.