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

Update all plugins for new storeReading method

parent a4bba18a
......@@ -290,6 +290,9 @@ Explanation of the values specific for the perfevent plugin:
| cpus | One can define a comma-separated list of cpu numbers (also value ranges can be specified, e.g. 2-4 equals 2,3,4). The hardware counter will then be only opened on the specified cpus.
> NOTE     As perfevent counters are usually always monotonic, the delta attribute is by default set to true for all sensors. One has to explicitly set delta to "off" for a sensor to overwrite this behaviour.
### type and config <a name="perfTypeConfig"></a>
(see the [perf_event_open man-page](http://man7.org/linux/man-pages/man2/perf_event_open.2.html) for more detailed explanations)
......
......@@ -80,7 +80,7 @@ public:
void setName(const std::string& name, int cpuID=-1) { _name = formatName(name, cpuID); }
void setMqtt(const std::string& mqtt) { _mqtt = mqtt; }
void setCacheInterval(unsigned cacheInterval) { _cacheInterval = cacheInterval; }
void setLastRawValue(uint64_t value) { _lastRawValue.value = value; }
const std::size_t getSizeOfReadingQueue() const { return _readingQueue->read_available(); }
std::size_t popReadingQueue(reading_t *reads, std::size_t max) const { return _readingQueue->pop(reads, max); }
......
......@@ -66,11 +66,11 @@ void BACnetSensorGroup::read() {
for(const auto& s : _sensors) {
try {
reading.value = _bacClient->readProperty(getDeviceInstance(), s->getObjectInstance(), s->getObjectType(), s->getPropertyId()) * s->getFactor();
reading.value = _bacClient->readProperty(getDeviceInstance(), s->getObjectInstance(), s->getObjectType(), s->getPropertyId());
#ifdef DEBUG
LOG(debug) << _groupName << "::" << s->getName() << ": \"" << reading.value << "\"";
#endif
s->storeReading(reading, _cacheSize);
s->storeReading(reading, s->getFactor());
} catch (const std::exception& e) {
LOG(error) << _groupName << "::" << s->getName() << " could not read value: " << e.what();
continue;
......
......@@ -86,7 +86,7 @@ void GpfsmonSensorGroup::read() {
auto upper = std::upper_bound(lower, searchEnd, nodename, GPFSSensorCompare());
for(;lower!=upper; ++lower){
reading.value = _data[(*lower)->getMetricType()];
(*lower)->storeReading(reading, _cacheSize);
(*lower)->storeReading(reading);
#ifdef DEBUG
LOG(debug) << _groupName << "::" << s->getName() << ": \"" << reading.value << "\"";
#endif
......
......@@ -71,14 +71,14 @@ void IPMISensorGroup::read() {
_host->getSdrRecord(s->getRecordId(), sdrRecord);
s->setSdrRecord(sdrRecord);
}
reading.value = _host->readSensorRecord(sdrRecord) * s->getFactor();
reading.value = _host->readSensorRecord(sdrRecord);
} else { /* use raw command */
reading.value = _host->sendRawCmd(s->getRawCmd(), s->getStart(), s->getStop()) * s->getFactor();
reading.value = _host->sendRawCmd(s->getRawCmd(), s->getStart(), s->getStop());
}
#ifdef DEBUG
LOG(debug) << _groupName << "::" << s->getName() << ": \"" << reading.value << "\"";
#endif
s->storeReading(reading, _cacheSize);
s->storeReading(reading, s->getFactor());
} catch (const std::exception& e) {
LOG(error) << _groupName << "::" << s->getName() << " could not read value: " << e.what();
continue;
......
......@@ -160,7 +160,7 @@ void OpaSensorGroup::read() {
continue;
break;
}
s->storeReading(reading, _cacheSize);
s->storeReading(reading);
#ifdef DEBUG
LOG(debug) << _groupName << "::" << s->getName() << ": \"" << reading.value << "\"";
#endif
......
......@@ -119,7 +119,7 @@ void PDUSensorGroup::read() {
#ifdef DEBUG
LOG(debug) << _groupName << "::" << s->getName() << ": \"" << reading.value << "\"";
#endif
s->storeReading(reading, _cacheSize);
s->storeReading(reading);
} catch (const std::exception& e) {
LOG(error) << _groupName << "::" << s->getName() << " could not read value: " << e.what();
continue;
......
......@@ -28,18 +28,6 @@ public:
void setType(unsigned type) { _type = type; }
void setConfig(unsigned config) { _config = config; }
void storeInReadingQueue(reading_t & reading, unsigned cacheSize) {
_readingQueue->push(reading);
_cache[_cacheIndex] = reading;
_cacheIndex = (_cacheIndex + 1) % cacheSize;
}
void setLatestValid(reading_t & reading, uint64_t valueNoCorrection){
_latestValue.value = valueNoCorrection;
_latestValue.timestamp = reading.timestamp;
}
protected:
unsigned int _type;
unsigned int _config;
......
......@@ -197,19 +197,17 @@ void PerfSensorGroup::read() {
for (unsigned j = 0; j < _sensors.size(); j++) {
if (rf->values[i].id == _ids[j]) {
//has no correction (might only overflow on uncorrected value)
reading_t lV = _sensors[j]->getLatestValue();
//first calculate interval and then apply correction to interval
reading.value = static_cast<uint64_t>(calculateIntervalValue(lV.value, val, PerfSensorBase::MAXCOUNTERVALUE)*correction);
reading.value = val;
#ifdef DEBUG
LOG(debug) << _groupName << "::" << _sensors[j]->getName() << ": \"" << reading.value << "\"";
#endif
if(_lastValid){
_sensors[j]->storeInReadingQueue(reading, _cacheSize);
//storeReading takes care of delta computation and applies correction value on the result
_sensors[j]->storeReading(reading, correction, PerfSensorBase::MAXCOUNTERVALUE);
} else {
//Before we can compute correct values again after an invalid reading we have to update the lastRawValue first
_sensors[j]->setLastRawValue(val);
}
//store original count (without correction) so we can compute the overflow and future intervals.
_sensors[j]->setLatestValid(reading, val);
break;
}
}
......@@ -234,10 +232,3 @@ void PerfSensorGroup::readAsync() {
}
_pendingTasks--;
}
uint64_t calculateIntervalValue(uint64_t previous, uint64_t current, uint64_t maxValue){
if(previous > current) { //overflow
return current + (maxValue - previous);
}
return current - previous;
}
......@@ -58,6 +58,8 @@ void PerfeventConfigurator::sensorBase(PerfSensorBase& s, CFG_VAL config) {
/*
* Custom code, as perf-event is an extra special plugin
*/
//default delta to true, as perfevent has only monotonic sensors usually
s.setDelta(true);
BOOST_FOREACH(boost::property_tree::iptree::value_type &val, config) {
if (boost::iequals(val.first, "type")) {
try {
......@@ -92,6 +94,9 @@ void PerfeventConfigurator::sensorBase(PerfSensorBase& s, CFG_VAL config) {
LOG(warning) << " Config \"" << val.second.data() << "\" not known.";
}
}
} else if (boost::iequals(val.first, "delta")) {
//it is explicitly stated to be off --> set it to false
s.setDelta( !(val.second.data() == "off") );
}
}
}
......@@ -194,7 +199,7 @@ bool PerfeventConfigurator::readConfig(std::string cfgPath) {
perfSG->setCpuId(*it);
perfSG->setMqttPart(formatMqttCPU(group.getMqttPart(), *it) + "/");
for(auto s : perfSG->getSensors()) s->setName(s->getName(), *it);
for(const auto& s : perfSG->getSensors()) s->setName(s->getName(), *it);
storeSensorGroup(perfSG);
leaderSG->pushBackGroup(perfSG);
......
......@@ -107,7 +107,7 @@ void ProcfsSensorGroup::read() {
else {
for(unsigned int i=0; i < this->_sensors.size(); i++) {
this->_readingBuffer.value = this->_readingVector->at(i).value;
this->_sensors.at(i)->storeReading(this->_readingBuffer, _cacheSize);
this->_sensors.at(i)->storeReading(this->_readingBuffer);
}
}
#ifdef DEBUG
......
......@@ -56,7 +56,7 @@ void SNMPSensorGroup::read() {
#ifdef DEBUG
LOG(debug) << _groupName << "::" << s->getName() << ": \"" << reading.value << "\"";
#endif
s->storeReading(reading, _cacheSize);
s->storeReading(reading);
} catch (const std::exception& e) {
LOG(error) << _groupName << "::" << s->getName() << " could not read value: " << e.what();
continue;
......
......@@ -76,7 +76,7 @@ void SysfsSensorGroup::read() {
#ifdef DEBUG
LOG(debug) << _groupName << "::" << s->getName() << ": \"" << reading.value << "\"";
#endif
s->storeReading(reading, _cacheSize);
s->storeReading(reading);
} catch (const std::exception& e) {
LOG(error) << _groupName << "::" << s->getName() << " could not read value: " << e.what();
continue;
......
Supports Markdown
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