Commit 56c77a58 authored by Alessio Netti's avatar Alessio Netti
Browse files

Tester plugin

- Allows to instantiate an arbitrary number of sensors which output
incremental values
- Naming and MQTT topic selection are performed automatically
- Useful to stress test the collectagent and verify overall performance
parent c8442902
......@@ -17,7 +17,7 @@ CXXFLAGS = -std=c++11 -DBOOST_DATE_TIME_POSIX_TIME_STD_CONFIG -DBOOST_NETWORK_EN
LIBS = -L../deps/mosquitto_build/lib -L$(DCDBDEPLOYPATH)/lib/ -ldl -lmosquitto -lboost_system -lboost_thread -lboost_log_setup -lboost_log -lboost_regex -lpthread -lcrypto -lssl -lcppnetlib-server-parsers -lcppnetlib-uri -rdynamic
OBJS = src/dcdbpusher.o src/Configuration.o src/MQTTPusher.o src/HttpsServer.o
PLUGINS = procfs pdu sysfs ipmi bacnet snmp
PLUGINS = procfs pdu sysfs ipmi bacnet snmp tester
ifeq ($(OS),Darwin)
BACNET_PORT = bsd
LIBEXT = dylib
......@@ -95,6 +95,9 @@ libdcdbplugin_snmp.$(LIBEXT): src/sensors/snmp/SNMPSensorGroup.o src/sensors/snm
libdcdbplugin_procfs.$(LIBEXT): src/sensors/procfs/ProcfsSensorGroup.o src/sensors/procfs/ProcfsParser.o src/sensors/procfs/ProcfsConfigurator.o
$(CXX) $(LIBFLAGS)$@ -o $@ $^ -L$(DCDBDEPLOYPATH)/lib/ -lboost_log -lboost_system -lboost_regex
libdcdbplugin_tester.$(LIBEXT): src/sensors/tester/TesterSensorGroup.o src/sensors/tester/TesterConfigurator.o
$(CXX) $(LIBFLAGS)$@ -o $@ $^ -L$(DCDBDEPLOYPATH)/lib/ -lboost_log -lboost_system
#libdcdbplugin_opa.$(LIBEXT): src/sensors/opa/OpaSensorGroup.o src/sensors/opa/OpaConfigurator.o
# $(CXX) $(LIBFLAGS)$@ -o $@ $^ -L$(DCDBDEPLOYPATH)/lib/ -lboost_log -lboost_system -lopamgt -libverbs -libumad -lssl
global {
mqttPrefix /FF112233445566778899AAB
}
template_group def1 {
interval 1000
minValues 3
mqttPart 000
startValue 0
}
group test1 {
default def1
mqttPart 00D
mqttStart 00
numSensors 250
}
group test2 {
default def1
mqttPart 00E
mqttStart 00
numSensors 250
}
/*
* TesterConfigurator.cpp
*
* Created on: 20.12.2018
* Author: Alessio Netti
*/
#include "TesterConfigurator.h"
TesterConfigurator::TesterConfigurator() {
_groupName = "group";
}
TesterConfigurator::~TesterConfigurator() {}
void TesterConfigurator::sensorBase(TesterSensorBase& s, CFG_VAL config) {}
void TesterConfigurator::sensorGroup(TesterSensorGroup& s, CFG_VAL config) {
std::string mqttStart="00";
unsigned int numSensors = 0;
BOOST_FOREACH(boost::property_tree::iptree::value_type &val, config)
{
if (boost::iequals(val.first, "numSensors")) {
numSensors = stoull(val.second.data());
} else if (boost::iequals(val.first, "startValue")) {
s.setValue(stoi(val.second.data()));
} else if (boost::iequals(val.first, "mqttStart")) {
mqttStart = val.second.data();
}
}
for(unsigned int i=0;i<numSensors;i++) {
TesterSensorBase *sensor = new TesterSensorBase(s.getGroupName() + std::to_string(i));
sensor->setMqtt(increaseMqtt(mqttStart, i));
s.pushBackSensor(sensor);
}
}
/*
* TesterConfigurator.h
*
* Created on: 20.12.2018
* Author: Alessio Netti
*/
#ifndef TESTERCONFIGURATOR_H_
#define TESTERCONFIGURATOR_H_
#include "../../includes/ConfiguratorTemplate.h"
#include "TesterSensorGroup.h"
class TesterConfigurator : public ConfiguratorTemplate<TesterSensorBase, TesterSensorGroup> {
public:
TesterConfigurator();
virtual ~TesterConfigurator();
protected:
/* Overwritten from ConfiguratorTemplate */
void sensorBase(TesterSensorBase& s, CFG_VAL config) override;
void sensorGroup(TesterSensorGroup& s, CFG_VAL config) override;
};
extern "C" ConfiguratorInterface* create() {
return new TesterConfigurator;
}
extern "C" void destroy(ConfiguratorInterface* c) {
delete c;
}
#endif /* TESTERCONFIGURATOR_H_ */
/*
* TesterSensorBase.h
*
* Created on: 20.12.2018
* Author: Alessio Netti
*/
#ifndef TESTER_TESTERSENSORBASE_H_
#define TESTER_TESTERSENSORBASE_H_
#include "../../includes/SensorBase.h"
class TesterSensorBase : public SensorBase {
public:
TesterSensorBase(const std::string& name) : SensorBase(name) {}
virtual ~TesterSensorBase() {}
};
#endif /* TESTER_TESTERSENSORBASE_H_ */
/*
* TesterSensorGroup.cpp
*
* Created on: 20.12.2018
* Author: Alessio Netti
*/
#include "timestamp.h"
#include <functional>
#include <cstring>
#include "TesterSensorGroup.h"
using namespace std;
TesterSensorGroup::TesterSensorGroup(const std::string& name) :
SensorGroupTemplate(name),
_value(0) {}
TesterSensorGroup::~TesterSensorGroup() {}
void TesterSensorGroup::start() {
if (_keepRunning) {
//we have been started already
LOG(info) << "Sensorgroup " << _groupName << " already running.";
return;
}
_keepRunning = 1;
_pendingTasks++;
_timer->async_wait(std::bind(&TesterSensorGroup::readAsync, this));
LOG(info) << "Sensorgroup " << _groupName << " started.";
}
void TesterSensorGroup::stop() {
_keepRunning = 0;
//wait before closing _file
wait();
LOG(info) << "Sensorgroup " << _groupName << " stopped.";
}
void TesterSensorGroup::read() {
// We don't care too much if _value overflows
reading_t reading;
reading.value = _value++;
reading.timestamp = getTimestamp();
for(auto s : _sensors) {
#ifdef DEBUG
LOG(debug) << _groupName << "::" << s->getName() << ": \"" << reading.value << "\"";
#endif
//to keep the _cacheIndex uniform for all sensors store value in every case
s->storeReading(reading, _cacheIndex);
}
_cacheIndex = (_cacheIndex + 1) % _cacheSize;
}
void TesterSensorGroup::readAsync() {
uint64_t now = getTimestamp();
read();
if (_timer && _keepRunning) {
uint64_t next = now + MS_TO_NS(_interval);
_timer->expires_at(timestamp2ptime(next));
_pendingTasks++;
_timer->async_wait(std::bind(&TesterSensorGroup::readAsync, this));
}
_pendingTasks--;
}
/*
* TesterSensorGroup.h
*
* Created on: 20.12.2018
* Author: Alessio Netti
*/
#ifndef TESTERSENSORGROUP_H_
#define TESTERSENSORGROUP_H_
#include "TesterSensorBase.h"
#include "../../includes/SensorGroupTemplate.h"
class TesterSensorGroup : public SensorGroupTemplate<TesterSensorBase> {
public:
TesterSensorGroup(const std::string& name);
virtual ~TesterSensorGroup();
void start() override;
void stop() override;
void setValue(long long n) { _value = n; }
private:
void read() override;
void readAsync() override;
long long _value;
};
#endif /* TESTERSENSORGROUP_H_ */
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