Variable monitoring
The DataMonitor class is a first step toward a tool allowing the monitoring of variables inside an actor.
One can add existing variables to the DataMonitor object and a list of desired statistics to compute. Available statistics are :
- RAW : the actual value
- MEAN : mean of the values from the beginning
- ROLLING_MEAN : mean of the N last values
- VARIANCE : variance from the beginning
- ROLLING_VARIANCE : variance on the N last values
- RATE : average variation per second between 2 reads
Example of usage :
int test = 5;
float test2 = 4.3;
AGAPRO::DataMonitor dm("test",5000); // name of the monitor and read frequency in ms
// adding some tags common to all variables
dm.add_tag("crystal_id",48);
dm.add_tag("actor","MyEmulator");
// adding variables to monitor
dm.add_variable("var1",test,{AGAPRO::MonitoringStat::RAW,AGAPRO::MonitoringStat::ROLLING_MEAN, AGAPRO::MonitoringStat::ROLLING_VARIANCE},5);
dm.add_variable("var2",test2,{AGAPRO::MonitoringStat::RAW,AGAPRO::MonitoringStat::RATE});
dm.start();//start the internal thread
// let's modify the variables
std::this_thread::sleep_for(std::chrono::milliseconds(10000));
test = 8;
std::this_thread::sleep_for(std::chrono::milliseconds(10000));
test2 = 5.6;
std::this_thread::sleep_for(std::chrono::milliseconds(10000));
test2 = 7.5;
test = 3;
std::this_thread::sleep_for(std::chrono::milliseconds(10000));
dm.stop();//stop the internal thread