Commit fab46443 authored by Micha Mueller's avatar Micha Mueller
Browse files

Adapt remaining plugins to new configurator architecture. Various fixes and improvements

parent 222f8b2e
......@@ -9,8 +9,8 @@ global {
cacheInterval 90
}
templates {
property def0 {
sensorTemplates {
sensor def0 {
factor 100
id 85
interval 1000
......
......@@ -5,7 +5,7 @@ global {
mqttprefix /AABBAABBAABBAACCDDCCDDCC
}
templateSensors {
sensorTemplates {
sensor energy {
; type raw
factor 0.001
......
......@@ -2,7 +2,7 @@ global {
mqttprefix /00112233445566778899AABBCCDD
}
SensorTemplate {
sensorTemplates {
sensor def1 {
interval 1000
minValues 3
......
CounterTemplate {
counter def1 {
sensorTemplates {
sensor def1 {
interval 5000
mqttsuffix 0222
minValues 5
......@@ -7,47 +7,47 @@ CounterTemplate {
config PERF_COUNT_HW_INSTRUCTIONS
}
counter def2 {
sensor def2 {
interval 2000
type PERF_TYPE_HARDWARE
cpus 1,2
}
}
counters {
counter hw_instructions {
sensors {
sensor hw_instructions {
default def1
mqttsuffix 0020
}
counter hw_branch_instructions {
sensor hw_branch_instructions {
default def2
mqttsuffix 0024
config PERF_COUNT_HW_BRANCH_INSTRUCTIONS
}
counter hw_branch_misses {
sensor hw_branch_misses {
default def2
mqttsuffix 002C
config PERF_COUNT_HW_BRANCH_MISSES
cpus 0,2-3
}
counter sw_pagefaults {
sensor sw_pagefaults {
interval 5000
mqttsuffix 0030
type PERF_TYPE_SOFTWARE
config PERF_COUNT_SW_PAGE_FAULTS
}
counter sw_context_switches {
sensor sw_context_switches {
interval 5000
mqttsuffix 0034
type PERF_TYPE_SOFTWARE
config PERF_COUNT_SW_CONTEXT_SWITCHES
}
counter sw_cpu_migrations {
sensor sw_cpu_migrations {
interval 5000
mqttsuffix 0038
type PERF_TYPE_SOFTWARE
......
......@@ -2,7 +2,7 @@ global {
mqttprefix /00112233445566778899AABBCC
}
templates {
sensorTemplates {
sensor temp1 {
interval 1000
minValues 3
......
......@@ -2,7 +2,7 @@ global {
mqttPrefix /FF112233445566778899AABBFFFF
}
SensorTemplate {
sensorTemplates {
sensor def1 {
path /home/micha/LRZ/dcdbOwnFork/sysfspusher/temp
interval 1000
......
......@@ -51,32 +51,38 @@ public:
boost::property_tree::read_info(cfgPath, cfg);
//read global variables (if present overwrite those from global.conf)
BOOST_FOREACH(boost::property_tree::iptree::value_type &global, cfg.get_child("global")) {
if (boost::iequals(global.first, "mqttprefix")) {
_mqttPrefix = global.second.data();
if (_mqttPrefix[_mqttPrefix.length()-1] != '/') {
_mqttPrefix.append("/");
boost::optional<boost::property_tree::iptree&> globalVals = cfg.get_child_optional("global");
if (globalVals) {
BOOST_FOREACH(boost::property_tree::iptree::value_type &global, cfg.get_child("global")) {
if (boost::iequals(global.first, "mqttprefix")) {
_mqttPrefix = global.second.data();
if (_mqttPrefix[_mqttPrefix.length()-1] != '/') {
_mqttPrefix.append("/");
}
LOG(debug) << " Using own MQTT-Prefix " << _mqttPrefix;
} else if (boost::iequals(global.first, "cacheInterval")) {
_cacheInterval = stoul(global.second.data());
LOG(debug) << " Using own caching interval " << _cacheInterval << " [s]";
_cacheInterval *= 1000;
} else {
LOG(error) << " Value \"" << global.first << "\" not recognized. Omitting for the moment";
}
LOG(debug) << " Using own MQTT-Prefix " << _mqttPrefix;
} else if (boost::iequals(global.first, "cacheInterval")) {
_cacheInterval = stoul(global.second.data());
LOG(debug) << " Using own caching interval " << _cacheInterval << " [s]";
_cacheInterval *= 1000;
} else {
LOG(error) << " Value \"" << global.first << "\" not recognized. Omitting...";
}
}
//read template sensors
BOOST_FOREACH(boost::property_tree::iptree::value_type &sens, cfg.get_child("templates")) {
if (boost::iequals(sens.first, "sensor")) {
LOG(debug) << "Template Sensor \"" << sens.second.data() << "\"";
if (!sens.second.empty()) {
S sensor(sens.second.data());
if(readSensor(sensor, sens.second)) {
_templateSensors.insert(std::pair<std::string, S>(sensor.getName(), sensor));
} else {
LOG(warning) << "Template sensor \"" << sens.second.data() << "\" has bad values! Ignoring...";
boost::optional<boost::property_tree::iptree&> tempSens = cfg.get_child_optional("sensorTemplates");
if (tempSens) {
BOOST_FOREACH(boost::property_tree::iptree::value_type &sensorVal, cfg.get_child("sensorTemplates")) {
if (boost::iequals(sensorVal.first, "sensor")) {
LOG(debug) << "Template Sensor \"" << sensorVal.second.data() << "\"";
if (!sensorVal.second.empty()) {
S sensor(sensorVal.second.data());
if(readSensor(sensor, sensorVal.second)) {
_templateSensors.insert(std::pair<std::string, S>(sensor.getName(), sensor));
} else {
LOG(warning) << "Template sensor \"" << sensorVal.second.data() << "\" has bad values! Ignoring...";
}
}
}
}
......@@ -146,8 +152,6 @@ protected:
BOOST_FOREACH(boost::property_tree::iptree::value_type &val, config) {
if (boost::iequals(val.first, "interval")) {
sensor.setInterval(stoull(val.second.data()));
} else if (boost::iequals(val.first, "mqttsuffix")) {
sensor.setMqtt(sensor.getMqtt() + val.second.data());
} else if (boost::iequals(val.first, "minValues")) {
sensor.setMinValues(stoull(val.second.data()));
} else {
......@@ -156,7 +160,6 @@ protected:
}
sensor.setCacheInterval(_cacheInterval);
LOG(debug) << " MQTT : " << sensor.getMqtt();
LOG(debug) << " Interval : " << sensor.getInterval();
LOG(debug) << " minValues: " << sensor.getMinValues();
......
......@@ -7,10 +7,7 @@
#include "BACnetConfigurator.h"
#include <boost/property_tree/info_parser.hpp>
#include <boost/foreach.hpp>
#include <boost/optional.hpp>
#include <boost/algorithm/string.hpp>
#include <iostream>
BACnetConfigurator::BACnetConfigurator() {
......@@ -23,11 +20,7 @@ BACnetConfigurator::~BACnetConfigurator() {
}
}
bool BACnetConfigurator::readConfig(std::string cfgPath) {
Configurator::readConfig(cfgPath);
boost::property_tree::iptree cfg;
boost::property_tree::read_info(cfgPath, cfg);
bool BACnetConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg) {
_bacClient = new BACnetClient();
std::string interface, address_cache, mqttPartDevice, mqttPartObject;
unsigned port = 47808, timeout = 1000, apdu_timeout = 200, apdu_retries = 0;
......@@ -55,15 +48,9 @@ bool BACnetConfigurator::readConfig(std::string cfgPath) {
apdu_retries = stoul(global.second.data());
LOG(debug) << " apdu_retries " << apdu_retries;
} else if (boost::iequals(global.first, "mqttprefix")) {
_mqttPrefix = global.second.data();
if (_mqttPrefix[_mqttPrefix.length()-1] != '/') {
_mqttPrefix.append("/");
}
LOG(debug) << " Using own MQTT-Prefix " << _mqttPrefix;
//avoid unnecessary "Value not recognized" messages
} else if (boost::iequals(global.first, "cacheInterval")) {
_cacheInterval = stoul(global.second.data());
LOG(debug) << " Using own caching interval " << _cacheInterval << " [s]";
_cacheInterval *= 1000;
//avoid unnecessary "Value not recognized" messages
} else {
LOG(error) << " Value \"" << global.first << "\" not recognized. Omitting...";
}
......@@ -76,21 +63,6 @@ bool BACnetConfigurator::readConfig(std::string cfgPath) {
return false;
}
//read template sensors
BOOST_FOREACH(boost::property_tree::iptree::value_type &sensor, cfg.get_child("templates")) {
if (boost::iequals(sensor.first, "property")) {
LOG(debug) << "Template Sensor \"" << sensor.second.data() << "\"";
if (!sensor.second.empty()) {
BACnetSensor bacnetSensor(sensor.second.data());
if(readSensor(bacnetSensor, sensor.second)) {
_templateSensors.insert(sensorMap_t::value_type(bacnetSensor.getName(), bacnetSensor));
} else {
LOG(warning) << "Template sensor \"" << sensor.second.data() << "\" has bad values! Ignoring...";
}
}
}
}
BOOST_FOREACH(boost::property_tree::iptree::value_type &device, cfg.get_child("devices")) {
if (boost::iequals(device.first, ("device"))) {
LOG(debug) << "Device " << device.second.data();
......@@ -140,8 +112,8 @@ bool BACnetConfigurator::readConfig(std::string cfgPath) {
bacSensor->setDeviceInstance(deviceInstance);
bacSensor->setObjectInstance(objInstance);
bacSensor->setObjectType(objType);
bacSensor->setMqtt(_mqttPrefix + mqttPartDevice + mqttPartObject);
bacSensor->setBACnetClient(_bacClient);
bacSensor->setMqtt(_mqttPrefix + mqttPartDevice + mqttPartObject);
//read remaining values
if(readSensor(*bacSensor, object.second)) {
_sensors.push_back(bacSensor);
......@@ -160,31 +132,30 @@ bool BACnetConfigurator::readConfig(std::string cfgPath) {
return true;
}
bool BACnetConfigurator::readSensor(BACnetSensor& sensor, boost::property_tree::iptree& config) {
void BACnetConfigurator::derivedReReadConfig() {
sleep(10);
delete _bacClient;
_bacClient = NULL;
}
bool BACnetConfigurator::derivedReadSensor(BACnetSensor& sensor, boost::property_tree::iptree& config) {
BOOST_FOREACH(boost::property_tree::iptree::value_type &val, config) {
if (boost::iequals(val.first, "interval")) {
sensor.setInterval(stoull(val.second.data()));
//avoid unnecessary "Value not recognized" messages
} else if (boost::iequals(val.first, "minValues")) {
} else if (boost::iequals(val.first, "default")) {
} else if (boost::iequals(val.first, "mqttsuffix")) {
//assume prefix mqtt part is already set in this sensor. Just append suffix
sensor.setMqtt(sensor.getMqtt() + val.second.data());
} else if (boost::iequals(val.first, "minValues")) {
sensor.setMinValues(stoull(val.second.data()));
} else if (boost::iequals(val.first, ("factor"))) {
sensor.setFactor(std::stod(val.second.data()));
} else if (boost::iequals(val.first, ("id"))) {
sensor.setPropertyId(static_cast<BACNET_PROPERTY_ID>(stoul(val.second.data())));
} else if (boost::iequals(val.first, "default")) {
//avoid unnecessary "Value not recognized" message
} else {
LOG(warning) << " Value \"" << val.first << "\" not recognized. Omitting...";
}
}
sensor.setCacheInterval(_cacheInterval);
LOG(debug) << " MQTTtopic:" << sensor.getMqtt();
LOG(debug) << " Interval : " << sensor.getInterval();
LOG(debug) << " minValues: " << sensor.getMinValues();
LOG(debug) << " MQTT : " << sensor.getMqtt();
LOG(debug) << " factor : " << sensor.getFactor();
LOG(debug) << " instance : " << sensor.getDeviceInstance();
LOG(debug) << " objInst : " << sensor.getObjectInstance();
......
......@@ -11,60 +11,30 @@
#include "BACnetSensor.h"
#include "BACnetClient.h"
#include <string>
#include <vector>
#include <map>
#include <boost/property_tree/ptree.hpp>
#include "../../ConfiguratorTemplate.h"
class BACnetConfigurator: public ConfiguratorTemplate<BACnetSensor> {
typedef std::map<std::string, BACnetSensor> sensorMap_t;
public:
BACnetConfigurator();
virtual ~BACnetConfigurator();
/**
* Read in the configuration for BACnet-sensors.
* @param cfgPath Path + name of the config-file
* @return true on success, false otherwise
*/
bool readConfig(std::string cfgPath);
//Overwrite from Configurator
bool reReadConfig() {
for (auto s : _sensors) {
s->stopPolling();
}
sleep(10);
delete _bacClient;
_bacClient = NULL;
_templateSensors.clear();
return ConfiguratorTemplate::reReadConfig();
}
protected:
bool derivedReadConfig(boost::property_tree::iptree& cfg) override;
void derivedReReadConfig() override;
void derivedSetGlobalSettings(const pluginSettings_t& pluginSettings) override {/*nothing to overwrite*/}
bool derivedReadSensor(BACnetSensor& sensor, boost::property_tree::iptree& config) override;
private:
/**
* Set the variables of sensor according to the values specified in config.
* @param sensor The sensor to be configured
* @param config A property(sub)tree containing the values
*
* @return True on success, false otherwise
*/
bool readSensor(BACnetSensor& sensor, boost::property_tree::iptree& config);
BACnetClient* _bacClient;
sensorMap_t _templateSensors;
};
extern "C" ConfiguratorTemplate* create() {
extern "C" ConfiguratorInterface* create() {
return new BACnetConfigurator;
}
extern "C" void destroy(ConfiguratorTemplate* c) {
extern "C" void destroy(ConfiguratorInterface* c) {
delete c;
}
......
......@@ -2,18 +2,12 @@
* IPMIConfigurator.cpp
*
* Created on: 26 Jan 2017
* Author: ottmi
* Author: Michael Ott (original), Micha Mueller
*/
#include "IPMIConfigurator.h"
#include "IPMIHost.h"
#include "IPMISensor.h"
#include <boost/property_tree/info_parser.hpp>
#include <boost/foreach.hpp>
#include <boost/optional.hpp>
#include <boost/algorithm/string.hpp>
#include <iostream>
namespace DCDB {
......@@ -25,54 +19,28 @@ IPMIConfigurator::IPMIConfigurator() {
IPMIConfigurator::~IPMIConfigurator() {}
bool IPMIConfigurator::readConfig(std::string cfgPath) {
Configurator::readConfig(cfgPath);
boost::property_tree::iptree cfg;
boost::property_tree::read_info(cfgPath, cfg);
bool IPMIConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg) {
//read global variables (if present overwrite those from global.conf)
BOOST_FOREACH(boost::property_tree::iptree::value_type &global, cfg.get_child("global")) {
if (boost::iequals(global.first, "SessionTimeout")) {
_globalHost.sessionTimeout = stoi(global.second.data());
LOG(debug) << " SessionTimeout " << _globalHost.sessionTimeout;
LOG(debug)<< " SessionTimeout " << _globalHost.sessionTimeout;
} else if (boost::iequals(global.first, "RetransmissionTimeout")) {
_globalHost.retransmissionTimeout = stoi(global.second.data());
LOG(debug) << " RetransmissionTimeout " << _globalHost.retransmissionTimeout;
} else if (boost::iequals(global.first, "mqttprefix")) {
_mqttPrefix = global.second.data();
if (_mqttPrefix[_mqttPrefix.length()-1] != '/') {
_mqttPrefix.append("/");
}
LOG(debug) << " Using own MQTT-Prefix " << _mqttPrefix;
//avoid unnecessary "Value not recognized" messages
} else if (boost::iequals(global.first, "cacheInterval")) {
_cacheInterval = stoul(global.second.data());
LOG(debug) << " Using own caching interval " << _cacheInterval << " [s]";
_cacheInterval *= 1000;
//avoid unnecessary "Value not recognized" messages
} else {
LOG(error) << " Value \"" << global.first << "\" not recognized. Omitting...";
}
}
//read template sensors
BOOST_FOREACH(boost::property_tree::iptree::value_type &sensor, cfg.get_child("templateSensors")) {
if (boost::iequals(sensor.first, "sensor")) {
LOG(debug) << "Template Sensor \"" << sensor.second.data() << "\"";
if (!sensor.second.empty()) {
DCDB::IPMISensor ipmiSensor(sensor.second.data());
if(readSensor(ipmiSensor, sensor.second)) {
_templateSensors.insert(sensorMap_t::value_type(ipmiSensor.getName(), ipmiSensor));
} else {
LOG(warning) << "Template sensor \"" << sensor.second.data() << "\" has bad values! Ignoring...";
}
}
}
}
BOOST_FOREACH(boost::property_tree::iptree::value_type &host, cfg.get_child("hosts")) {
if (boost::iequals(host.first, ("host"))) {
LOG(debug) << "Host " << host.second.data();
_hosts.push_back(DCDB::IPMIHost(host.second.data(), _globalHost.retransmissionTimeout, _globalHost.sessionTimeout));
LOG(debug)<< "Host " << host.second.data();
_hosts.push_back(DCDB::IPMIHost(host.second.data(), _globalHost.retransmissionTimeout, _globalHost.sessionTimeout));
DCDB::IPMIHost &ipmiHost = _hosts.back();
ipmiHost.setMqttPrefix(_mqttPrefix);
ipmiHost.setCache(_tempdir);
......@@ -126,22 +94,27 @@ bool IPMIConfigurator::readConfig(std::string cfgPath) {
return true;
}
bool IPMIConfigurator::readSensor(DCDB::IPMISensor& sensor, boost::property_tree::iptree& config) {
void IPMIConfigurator::derivedReReadConfig() {
sleep(10);
_hosts.clear();
}
bool IPMIConfigurator::derivedReadSensor(DCDB::IPMISensor& sensor, boost::property_tree::iptree& config) {
BOOST_FOREACH(boost::property_tree::iptree::value_type &val, config) {
if (boost::iequals(val.first, "interval")) {
sensor.setInterval(stoull(val.second.data()));
//avoid unnecessary "Value not recognized" messages
} else if (boost::iequals(val.first, "minValues")) {
} else if (boost::iequals(val.first, "default")) {
} else if (boost::iequals(val.first, "mqttsuffix")) {
if (sensor.getHost() != NULL) {
// only workaround so that every host can define own prefix
// not guaranteed, but should actually work as long as prefix is defined before the sensors within a host
if (sensor.getHost()->getMqttPrefix() != "") {
sensor.setMqtt(sensor.getHost()->getMqttPrefix() + val.second.data());
} else {
sensor.setMqtt(_mqttPrefix + val.second.data());
}
} else {
sensor.setMqtt(_mqttPrefix + val.second.data());
}
} else if (boost::iequals(val.first, "minValues")) {
sensor.setMinValues(stoull(val.second.data()));
} else if (boost::iequals(val.first, ("cmd"))) {
sensor.setRawCmd(val.second.data());
} else if (boost::iequals(val.first, "start")) {
......@@ -152,18 +125,12 @@ bool IPMIConfigurator::readSensor(DCDB::IPMISensor& sensor, boost::property_tree
sensor.setRecordId(stoul(val.second.data()));
} else if (boost::iequals(val.first, ("factor"))) {
sensor.setFactor(std::stod(val.second.data()));
} else if (boost::iequals(val.first, "default")) {
//avoid unnecessary "Value not recognized" message
} else {
LOG(warning) << " Value \"" << val.first << "\" not recognized. Omitting...";
LOG(warning)<<" Value \"" << val.first << "\" not recognized. Omitting...";
}
}
sensor.setCacheInterval(_cacheInterval);
LOG(debug) << " MQTTSuffix:" << sensor.getMqtt();
LOG(debug) << " Interval : " << sensor.getInterval();
LOG(debug) << " minValues: " << sensor.getMinValues();
LOG(debug) << " MQTT : " << sensor.getMqtt();
LOG(debug) << " factor : " << sensor.getFactor();
if (sensor.getRecordId() != 0) {
LOG(debug) << " RecordID : " << sensor.getRecordId();
......@@ -175,4 +142,5 @@ bool IPMIConfigurator::readSensor(DCDB::IPMISensor& sensor, boost::property_tree
return true;
}
} /* namespace DCDB */
}
/* namespace DCDB */
......@@ -2,7 +2,7 @@
* IPMIConfigurator.h
*
* Created on: 26 Jan 2017
* Author: ottmi
* Author: Michael Ott (original), Micha Mueller
*/
#ifndef IPMICONFIGURATOR_H_
......@@ -10,71 +10,44 @@
#include "IPMISensor.h"
#include "IPMIHost.h"
#include <boost/property_tree/ptree.hpp>
#include <string>
#include <map>
#include <list>
#include <vector>
#include "../../ConfiguratorTemplate.h"
namespace DCDB {
class IPMIConfigurator : public ConfiguratorTemplate<IPMISensor> {
class IPMIConfigurator: public ConfiguratorTemplate<DCDB::IPMISensor> {
typedef std::list<DCDB::IPMIHost> hostList_t;
typedef std::map<std::string, DCDB::IPMISensor> sensorMap_t;
typedef struct {
uint32_t sessionTimeout;
uint32_t retransmissionTimeout;
} globalHost_t;
public:
IPMIConfigurator();
virtual ~IPMIConfigurator();
bool readConfig(std::string cfgPath);
//Overwrite from Configurator
void setGlobalSettings(const pluginSettings_t& pluginSettings) {
ConfiguratorTemplate::setGlobalSettings(pluginSettings);
_tempdir = pluginSettings.tempdir;
}
//Overwrite from Configurator
bool reReadConfig() {
for (auto s : _sensors) {
s->stopPolling();
}
sleep(10);
_hosts.clear();
_templateSensors.clear();
return ConfiguratorTemplate::reReadConfig();
}
public:
IPMIConfigurator();
virtual ~IPMIConfigurator();
private:
/**
* Set the variables of sensor according to the values specified in config.
* @param sensor The sensor to be configured
* @param config A property(sub)tree containing the values
*
* @return True on success, false otherwise
*/
bool readSensor(IPMISensor& sensor, boost::property_tree::iptree& config);
protected:
bool derivedReadConfig(boost::property_tree::iptree& cfg) override;
void derivedReReadConfig() override;
void derivedSetGlobalSettings(const pluginSettings_t& pluginSettings) override { _tempdir = pluginSettings.tempdir; }
bool derivedReadSensor(DCDB::IPMISensor& sensor, boost::property_tree::iptree& config) override;
std::string _tempdir;
sensorMap_t _templateSensors;
hostList_t _hosts;
globalHost_t _globalHost;
};
private:
std::string _tempdir;
hostList_t _hosts;
globalHost_t _globalHost;