Commit 2e446288 authored by lu43jih's avatar lu43jih
Browse files

Fixing bugs in gpfsmon (previous version was only compilable)

parent 2cc27930
......@@ -57,6 +57,14 @@ void ${PLUGIN_NAME}SensorGroup::stop() {
LOG(info) << "Sensorgroup " << _groupName << " stopped.";
}
void ${PLUGIN_NAME}SensorGroup::init(boost::asio::io_service& io) {
SensorGroupTemplate::init(io);
/**
* TODO Initialize here Sensor Group or remove this member function completely
* The SensorGroupTemplate::init(io); will then be called
*/
}
void ${PLUGIN_NAME}SensorGroup::read() {
reading_t reading;
reading.timestamp = getTimestamp();
......
......@@ -10,10 +10,11 @@
#include "timestamp.h"
#include <algorithm>
#include <fstream>
#include <sys/stat.h>
GpfsmonSensorGroup::GpfsmonSensorGroup(const std::string& name) :
SensorGroupTemplate(name) {
createTempFile();
if(!fileExists(TMP_GPFSMON)) createTempFile();
_data.resize(GPFS_METRIC::SIZE);
}
......@@ -26,6 +27,7 @@ GpfsmonSensorGroup& GpfsmonSensorGroup::operator=(const GpfsmonSensorGroup& othe
GpfsmonSensorGroup::GpfsmonSensorGroup(const GpfsmonSensorGroup& other):
SensorGroupTemplate<GpfsmonSensorBase>(other){
_data.resize(GPFS_METRIC::SIZE);
if(!fileExists(TMP_GPFSMON)) createTempFile();
}
GpfsmonSensorGroup::~GpfsmonSensorGroup() {
......@@ -69,10 +71,12 @@ void GpfsmonSensorGroup::read() {
}
} else {
LOG(error) << "Sensorgroup" << _groupName << " could not parse line" << buf;
//assume there was a problem with the temp file
if(!fileExists(TMP_GPFSMON)) createTempFile();
}
}
} else { //assume there was a problem with the temp file
createTempFile();
} else {
LOG(error) << "Sensorgroup" << _groupName << " popen failed, check if you have enough file descriptors.";
}
} catch (const std::exception& e) {
LOG(error) << "Sensorgroup" << _groupName << " could not read value: " << e.what();
......@@ -92,7 +96,7 @@ void GpfsmonSensorGroup::readAsync() {
void GpfsmonSensorGroup::createTempFile(){
std::ofstream gpfsmonFile;
gpfsmonFile.open("/tmp/gpfsmon");
gpfsmonFile.open(TMP_GPFSMON);
if(gpfsmonFile.is_open()){
gpfsmonFile << "io_s\n";
gpfsmonFile.close();
......@@ -101,6 +105,18 @@ void GpfsmonSensorGroup::createTempFile(){
}
}
void GpfsmonSensorGroup::init(boost::asio::io_service& io) {
SensorGroupTemplate::init(io);
if(!fileExists(TMP_GPFSMON)) createTempFile();
_data.resize(GPFS_METRIC::SIZE);
}
bool GpfsmonSensorGroup::fileExists(const char* filename){
//https://stackoverflow.com/questions/12774207/fastest-way-to-check-if-a-file-exist-using-standard-c-c11-c
struct stat buffer;
return (stat (filename, &buffer) == 0);
}
bool GpfsmonSensorGroup::parseLine(std::string &&toparse){
std::string::size_type bytereads_pos = toparse.find("_br_ ");
std::string::size_type bytewrite_pos = toparse.find(" _bw_ ");
......
......@@ -30,6 +30,7 @@ private:
void read() override;
void readAsync() override;
bool fileExists(const char* filename);
void createTempFile();
bool parseLine(std::string &&toparse);
......@@ -37,6 +38,7 @@ private:
std::vector<int64_t> _data; //!< temp variable in parseLine defined here for efficiency.
constexpr static int BUFFER_SIZE=255; //!< constant buffer that is used to parse line by line (from popen)
char const * TMP_GPFSMON="/tmp/gpfsmon";
};
......
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