Commit 5bfdde71 authored by Alessio Netti's avatar Alessio Netti
Browse files

ProcFS plugin changes

- Switch from the STD regex library (which apparently is incomplete for GCC < 4.9) to the BOOST one
- Plugin is stable and tested on a CoolMUC3 node
- Current overhead for a full vmstat + meminfo + procstat instantiation is 1.3% on a CoolMUC 3 node with 256 (logical) cores
- More optimization work to come
parent fd81ab3d
......@@ -94,7 +94,7 @@ libdcdbplugin_snmp.$(LIBEXT): src/sensors/snmp/SNMPSensorGroup.o src/sensors/snm
$(CXX) $(LIBFLAGS)$@ -o $@ $^ -L$(DCDBDEPLOYPATH)/lib/ -lboost_log -lboost_system -lnetsnmp -lnetsnmpagent
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
$(CXX) $(LIBFLAGS)$@ -o $@ $^ -L$(DCDBDEPLOYPATH)/lib/ -lboost_log -lboost_system -lboost_regex
#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
......@@ -147,7 +147,8 @@ void ProcfsConfigurator::sensorGroup(ProcfsSensorGroup& sGroup, CFG_VAL config)
else {
LOG(warning) << _groupName << " " << sGroup.getGroupName() << "::" << "Unspecified or invalid type! Available types are vmstat, meminfo, procstat";
return; }
sGroup.setType(fileType);
// Probing the target file to be monitored and counting the available metrics
parser->init();
std::vector<std::string> *availableMetrics = parser->readNames();
......@@ -159,7 +160,9 @@ void ProcfsConfigurator::sensorGroup(ProcfsSensorGroup& sGroup, CFG_VAL config)
}
LOG(debug) << " Number of metrics found: " << numMetrics;
// Assigning the parser to the sensor group
sGroup.setParser(parser);
// Vector that keeps track of the current number of metrics for each CPU core for which a MQTT topic has been assigned
// All core-independent metrics refer to position 0 in the vector
std::vector<unsigned int> *metricsCounter = new std::vector<unsigned int>(parser->getNumCPUs() + 1);
......@@ -190,7 +193,4 @@ void ProcfsConfigurator::sensorGroup(ProcfsSensorGroup& sGroup, CFG_VAL config)
// De-allocating memory and restoring the parser to its default state
delete metricsCounter;
parser->close();
// Assigning the parser to the sensor group
sGroup.setParser(parser);
sGroup.setType(fileType);
}
......@@ -220,10 +220,10 @@ std::vector<std::string> *ProcstatParser::_readNames() {
}
// We check whether the line is cpu core-related or not through a regular expression
// If the name contains the "cpu" keyword, then it is cpu-related
if( std::regex_search(lineToken, this->_match, this->reg_exp) ) {
if( boost::regex_search(lineToken, this->_match, this->reg_exp) ) {
// If a match to an integer number is found within the name, the metric is related to a specific core. Otherwise,
// it is considered as a system-wide metric
try { currCPU = !std::regex_search(lineToken, this->_match, reg_exp_num) ? -1 : (short)std::stol(this->_match.str(0)); }
try { currCPU = !boost::regex_search(lineToken, this->_match, reg_exp_num) ? -1 : (short)std::stol(this->_match.str(0)); }
catch (const std::invalid_argument& ia) { return NULL; }
catch (const std::out_of_range& oor) { return NULL; }
// The number of CPU cores in the system is inferred from the maximum CPU ID found while parsing
......@@ -273,7 +273,7 @@ std::vector<reading_t> *ProcstatParser::_readMetrics() {
// First token is discarded, represents the metric's name
if(lineToken == NULL) return NULL;
// We check whether the line is CPU core-related or not (see _readNames)
if( std::regex_search(lineToken, this->_match, this->reg_exp) ) {
if( boost::regex_search(lineToken, this->_match, this->reg_exp) ) {
ctrInner = 0;
// We iterate over the line and capture all of the CPU core-related metrics
while( (lineToken = strtok_r(NULL, this->LINE_SEP, &savePtr)) != NULL ) {
......
......@@ -10,9 +10,10 @@
#define PROCFSPARSER_H_
#include "../../includes/SensorBase.h"
#include <boost/regex.hpp>
#include <vector>
#include <string>
#include <regex>
#include <string.h>
#include <exception>
/**
......@@ -112,14 +113,14 @@ protected:
// Internal variables
unsigned short _actualMetrics;
std::cmatch _match;
boost::cmatch _match;
// The number of known metrics in each "cpu" line together with their names, as of Oct. 2018
enum { DEFAULTMETRICS = 10 };
const std::string DEFAULT_NAMES[DEFAULTMETRICS] = {"user", "nice", "system", "idle", "iowait", "irq", "softirq", "steal", "guest", "guest_nice"};
// Regex to match strings beginning with the "cpu" keyword
const std::regex reg_exp = std::regex("^cpu");
const boost::regex reg_exp = boost::regex("^cpu");
// Regex to match strings ending with integer numbers (in this case, CPU core IDs)
const std::regex reg_exp_num = std::regex("[0-9]+$");
const boost::regex reg_exp_num = boost::regex("[0-9]+$");
};
#endif /* PROCFSPARSER_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