Commit f03468ea authored by Alessio Netti's avatar Alessio Netti
Browse files

Analytics: testerOperator now supports both flat and hierarchical units

- This is meant as a proof of concept of how the new flat/hierarchical
unit system can be configured to obtain different results
- Output sensors in sub-units contain the respective query counter, whereas
the top-level unit's output sensor contains a global query counter
parent 12af40ab
......@@ -14,20 +14,25 @@ default def1
window 2000
relative false
input {
unitInput {
sensor "<bottomup>col_user"
sensor "<topdown>MemFree"
sensor "<bottomup, filter cpu>col_user"
sensor "<bottomup 1>MemFree"
}
output {
unitOutput {
sensor "<bottomup>queries" {
mqttsuffix /queries
}
}
; If globalOutput is defined, all units described by the unitInput and unitOutput blocks will be grouped
; in a single hierarchical unit
globalOutput {
sensor totalQueries {
mqttsuffix /totalQueries
}
}
}
......
......@@ -49,6 +49,19 @@ void TesterOperator::printConfig(LOG_LEVEL ll) {
}
void TesterOperator::compute(U_Ptr unit) {
if(unit->isTopUnit()) {
reading_t outR;
outR.timestamp = getTimestamp();
uint64_t globCtr=0;
for(const auto& subUnit : unit->getSubUnits())
globCtr += compute_internal(subUnit);
outR.value = (int64_t)globCtr;
unit->getOutputs()[0]->storeReading(outR);
} else
compute_internal(unit);
}
uint64_t TesterOperator::compute_internal(U_Ptr unit) {
bool errorLog=false;
reading_t outR;
outR.timestamp = getTimestamp();
......@@ -72,4 +85,5 @@ void TesterOperator::compute(U_Ptr unit) {
LOG(error) << "Operator " << _name << ": could not read from one or more sensors!";
outR.value = (int64_t)elCtr;
unit->getOutputs()[0]->storeReading(outR);
return elCtr;
}
......@@ -60,6 +60,7 @@ public:
protected:
virtual void compute(U_Ptr unit) override;
uint64_t compute_internal(U_Ptr unit);
vector<reading_t> _buffer;
unsigned long long _window;
......
......@@ -48,11 +48,17 @@ void TesterOperatorConfigurator::operatorAttributes(TesterOperator& op, CFG_VAL
}
}
bool TesterOperatorConfigurator::unit(UnitTemplate<SensorBase>& u) {
if(u.getOutputs().size()!=1) {
LOG(error) << " " << _operatorName << ": Only one output sensor per unit is allowed!";
return false;
}
else
return true;
bool TesterOperatorConfigurator::unit(UnitTemplate<SensorBase>& u) {
if(u.getOutputs().size()!=1) {
LOG(error) << " " << _operatorName << ": Only one output sensor in the top unit is allowed!";
return false;
}
if(u.isTopUnit())
for(const auto& subUnit : u.getSubUnits())
if(subUnit->getOutputs().size()!=1) {
LOG(error) << " " << _operatorName << ": Only one output sensor per sub unit is allowed!";
return false;
}
return true;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment