This crate provides a beginner-friendly example of using the DeepCausality library to monitor a server's health by fusing data from multiple sensors.
Specifically, this example models a simple server with three sensors:
- Fan Speed
- CPU Temperature
- Power Draw
A warning is triggered only when all three sensors report a "high" reading simultaneously, indicating a potential risk of failure.
This showcases how the EPP's CausaloidCollection can be used for sensor fusion, and how a CausalState can trigger an CausalAction based on the fused data.
From the root of the deep_causality project, run:
cargo run -p csm_examples --example csm_context_example-
Individual Sensor Logic (
Causaloids):- The logic for each sensor is encapsulated in a simple
Causaloid. - For example, the
cpu_temp_causaloidchecks if a numerical input (the temperature reading) exceeds a predefined "high" threshold.
- The logic for each sensor is encapsulated in a simple
-
**Sensor Fusion (
CausaloidCollection):- The three sensor
Causaloids are grouped into aCausaloidCollection. - The collection's
AggregateLogicis set toAll, meaning the collection as a whole will only evaluate totrueif all of its containedCausaloids evaluate totrue.
- The three sensor
-
**Server State (
Context):- A
BaseContextis used to represent the server's current state. - It holds three
Datoids, each storing the latest reading from one of the sensors.
- A
-
**State-Based Action (
CSM):- A
CausalStateis defined, using theCausaloidCollectionas its evaluation logic. This state becomes active only when all sensors are high. - A
CausalActionis defined to print a warning message to the console. - A
CSM(Causal State Machine) links the "high load" state to the warning action.
- A
-
**Simulation:
- The
mainfunction simulates two scenarios by creating aPropagatingEffect::Mapwith different sensor readings. - In the "Normal Load" scenario, not all readings are high, so the
CausaloidCollectionevaluates tofalse, and the CSM does not fire the action. - In the "High Load" scenario, all readings are high, the collection evaluates to
true, theCausalStatebecomes active, and the CSM fires the warning action.
- The