Commit 17ef5652 authored by lu43jih's avatar lu43jih
Browse files

Working on Gpfsmon plugin

parent d241ada1
......@@ -12,41 +12,38 @@
#include <fstream>
/**
* Comparation functor for GpfsmonSensorBase.
* No lambda used since the same function is needed in more than one place...
* Comparison functor for GpfsmonSensorBase.
*/
struct SensorCompare {
struct GPFSSensorCompare {
bool operator()(const Gpfs_SB& lhs, const Gpfs_SB & rhs) const {
return (lhs->getNodeName() < rhs->getNodeName()) || ( lhs->getNodeName() == rhs->getNodeName() && lhs->getMetricType() < rhs->getMetricType());
return lhs->getNodeName() < rhs->getNodeName();
}
bool operator()(const Gpfs_SB& lhs, const std::string & rhs) const {
return lhs->getNodeName() < rhs;
}
bool operator()(const std::string & lhs, const Gpfs_SB& rhs ) const {
return lhs < rhs->getNodeName();
}
};
GpfsmonSensorGroup::GpfsmonSensorGroup(const std::string& name) :
SensorGroupTemplate(name) {
createTempFile();
makeDummy();
}
GpfsmonSensorGroup& GpfsmonSensorGroup::operator=(const GpfsmonSensorGroup& other){
SensorGroupTemplate<GpfsmonSensorBase>::operator=(other);
data = other.data; //copy of vectors
makeDummy(); //no need to copy the state of dummy
return *this;
SensorGroupTemplate<GpfsmonSensorBase>::operator=(other);
_data = other._data; //copy of vectors
return *this;
}
GpfsmonSensorGroup::GpfsmonSensorGroup(const GpfsmonSensorGroup& other):
SensorGroupTemplate<GpfsmonSensorBase>(other){
data = other.data;
makeDummy();
}
void GpfsmonSensorGroup::makeDummy(){
searchDummy = std::make_shared<GpfsmonSensorBase>("Dummy");
SensorGroupTemplate<GpfsmonSensorBase>(other){
_data = other._data;
}
GpfsmonSensorGroup::~GpfsmonSensorGroup() {
data.clear();
_data.clear();
}
void GpfsmonSensorGroup::start() {
......@@ -56,7 +53,7 @@ void GpfsmonSensorGroup::start() {
return;
}
std::sort(_sensors.begin(), _sensors.end(),SensorCompare());
std::sort(_sensors.begin(), _sensors.end(),GPFSSensorCompare());
_keepRunning = 1;
_pendingTasks++;
......@@ -66,12 +63,6 @@ void GpfsmonSensorGroup::start() {
void GpfsmonSensorGroup::stop() {
_keepRunning = 0;
/*
* TODO
* Stop plugin specific stuff
*/
LOG(info) << "Sensorgroup " << _groupName << " stopped.";
}
......@@ -80,63 +71,22 @@ void GpfsmonSensorGroup::read() {
reading.timestamp = getTimestamp();
try {
std::string toparse;
FILE *pf = popen(cmd_io.c_str(),"r");
FILE *pf = popen(_cmd_io.c_str(),"r");
if (pf != nullptr) {
char buf[BUFFER_SIZE];
while (fgets(buf, BUFFER_SIZE, pf) != nullptr) {
toparse= std::string(buf);
//ToDo parse nodename here
std::string nodename = "blabla";
searchDummy->setNodeName(nodename);
std::string::size_type bytereads_pos = toparse.find("_br_ ");
std::string::size_type bytewrite_pos = toparse.find(" _bw_ ");
if( bytereads_pos != std::string::npos && bytewrite_pos != std::string::npos){
data[IOBYTESREAD] = std::stoull(toparse.substr(bytereads_pos + 5, bytewrite_pos - bytereads_pos));
} else {
//ToDo log error?
break;
}
std::string::size_type opens_pos = toparse.find(" _oc_ ");
if( opens_pos != std::string::npos ){
data[IOBYTESWRITE] = std::stoull(toparse.substr(bytewrite_pos + 6, opens_pos - bytewrite_pos));
} else {
break;
}
std::string::size_type closes_pos = toparse.find(" _cc_ ");
if( closes_pos != std::string::npos){
data[IOOPENS] = std::stoull(toparse.substr(opens_pos + 6, closes_pos - opens_pos));
} else {
break;
}
std::string::size_type reads_pos = toparse.find(" _rdc_ ");
if( reads_pos != std::string::npos ){
data[IOCLOSES] = std::stoull(toparse.substr(closes_pos + 6, reads_pos - closes_pos));
} else {
break;
}
std::string::size_type writes_pos = toparse.find(" _wc_ ");
if( writes_pos != std::string::npos ){
data[IOREADS] = std::stoull(toparse.substr(reads_pos + 7, writes_pos - reads_pos));
} else {
break;
}
std::string::size_type dir_pos = toparse.find(" _dir_");
if( dir_pos != std::string::npos ){
data[IOWRITES] = std::stoull(toparse.substr(writes_pos + 6, dir_pos - writes_pos));
} else {
break;
}
for(unsigned int i=1; i< static_cast<unsigned int>(GPFS_METRIC::SIZE); ++i){
reading.value = data[i];
searchDummy->setMetricType(static_cast<GPFS_METRIC>(i));
auto found = std::lower_bound(_sensors.begin(), _sensors.end(), searchDummy, SensorCompare());
if(found != _sensors.end()){
(*found)->storeReading(reading, _cacheSize);
auto lower = std::lower_bound(_sensors.begin(), _sensors.end(), nodename, GPFSSensorCompare());
if(lower != _sensors.end()){
parseLine(std::string(buf));
auto searchEnd = lower+ GPFS_METRIC::SIZE;
auto upper = std::upper_bound(lower, searchEnd, nodename, GPFSSensorCompare());
for(;lower!=upper; ++lower){
reading.value = _data[(*lower)->getMetricType()];
(*lower)->storeReading(reading, _cacheSize);
#ifdef DEBUG
LOG(debug) << _groupName << "::" << s->getName() << ": \"" << reading.value << "\"";
#endif
......@@ -154,8 +104,7 @@ void GpfsmonSensorGroup::readAsync() {
uint64_t now = getTimestamp();
read();
if (_timer && _keepRunning) {
uint64_t next = now + MS_TO_NS(_interval);
_timer->expires_at(timestamp2ptime(next));
_timer->expires_at(timestamp2ptime(nextReadingTime()));
_pendingTasks++;
_timer->async_wait(std::bind(&GpfsmonSensorGroup::readAsync, this));
}
......@@ -173,3 +122,44 @@ void GpfsmonSensorGroup::createTempFile(){
}
}
void GpfsmonSensorGroup::parseLine(std::string &&toparse){
std::string::size_type bytereads_pos = toparse.find("_br_ ");
std::string::size_type bytewrite_pos = toparse.find(" _bw_ ");
if( bytereads_pos != std::string::npos && bytewrite_pos != std::string::npos){
_data[IOBYTESREAD] = std::stoull(toparse.substr(bytereads_pos + 5, bytewrite_pos - bytereads_pos));
} else {
//ToDo log error?
return;
}
std::string::size_type opens_pos = toparse.find(" _oc_ ");
if( opens_pos != std::string::npos ){
_data[IOBYTESWRITE] = std::stoull(toparse.substr(bytewrite_pos + 6, opens_pos - bytewrite_pos));
} else {
return;
}
std::string::size_type closes_pos = toparse.find(" _cc_ ");
if( closes_pos != std::string::npos){
_data[IOOPENS] = std::stoull(toparse.substr(opens_pos + 6, closes_pos - opens_pos));
} else {
return;
}
std::string::size_type reads_pos = toparse.find(" _rdc_ ");
if( reads_pos != std::string::npos ){
_data[IOCLOSES] = std::stoull(toparse.substr(closes_pos + 6, reads_pos - closes_pos));
} else {
return;
}
std::string::size_type writes_pos = toparse.find(" _wc_ ");
if( writes_pos != std::string::npos ){
_data[IOREADS] = std::stoull(toparse.substr(reads_pos + 7, writes_pos - reads_pos));
} else {
return;
}
std::string::size_type dir_pos = toparse.find(" _dir_");
if( dir_pos != std::string::npos ){
_data[IOWRITES] = std::stoull(toparse.substr(writes_pos + 6, dir_pos - writes_pos));
} else {
return;
}
}
......@@ -31,13 +31,12 @@ private:
void readAsync() override;
void createTempFile();
void makeDummy();
void parseLine(std::string &&toparse);
const std::string cmd_io = "/usr/lpp/mmfs/bin/mmpmon -p -i /tmp/gpfsmon"; //todo change to real command
const std::string _cmd_io = "/usr/lpp/mmfs/bin/mmpmon -p -i /tmp/gpfsmon"; //todo change to real command
Gpfs_SB searchDummy;
std::vector<uint64_t> data;
constexpr static int BUFFER_SIZE=255; //!< constant buffer that is parse by a line given from the popen command
std::vector<uint64_t> _data;
constexpr static int BUFFER_SIZE=255; //!< constant buffer that is used to parse line by line (from popen)
};
......
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