Commit 09c6fcfd authored by Michael Ott's avatar Michael Ott
Browse files

Remove deprecated Gpfsmon and GpfsmonConfigurator files

parent fadec908
/*
* Gpfsmon.cpp
*
* Created on: 03.09.2018
* Author: lu43jih
*/
#include "Gpfsmon.h"
#include <fstream>
#include "timestamp.h"
#include "../sensorutils/utilities.h"
#include <string>
Gpfsmon::Gpfsmon(const std::string& name, std::string& mqttPrefix): MultiSensor(name), _mqttPrefix(mqttPrefix) {
createTempFile();
}
Gpfsmon::~Gpfsmon() {
}
void Gpfsmon::read() {
std::string cmd_io = "/usr/lpp/mmfs/bin/mmpmon -p -i /tmp/gpfsmon";
//example output:
//_io_s_ _n_ 10.6.2.99 _nn_ login10-ib _rc_ 0 _t_ 1535982026 _tu_ 31689 _br_ 105392053055 _bw_ 120062962186 _oc_ 2427218 _cc_ 2394471 _rdc_ 1268080 _wc_ 58787 _dir_ 2107795 _iu_ 21191231
Popen<IOData> mmpmon(cmd_io);
mmpmon.doPopen(_afterIOData);
reading_t reading;
reading.timestamp = getTimestamp();
if (_afterIOData.size() == 1) {
if(_beforeIOData.size() == 1){
for(auto &mqttS2Miid : mqttSuffixToInternalId){
std::string mqttSuffix = mqttS2Miid.first;
std::string mqttID = createIDFromMqttParts(_mqttPrefix, 0, mqttSuffix);
auto found = _readingQueuesMap.find(mqttID);
if(found != _readingQueuesMap.end()){
IOData res = *(_afterIOData[0].get()) - *(_beforeIOData[0].get());
reading.value = res.getMetric(mqttS2Miid.second.internalMetricId);
found->second->push(reading);
} else {
LOG(error) << "Gpfsmon: unable to find MqttID=" << mqttID;
}
}
}
_beforeIOData = std::move(_afterIOData);
_afterIOData.clear();
} else { //create temp file just in case...
createTempFile();
}
}
void Gpfsmon::createTempFile(){
std::ofstream gpfsmonFile;
gpfsmonFile.open("/tmp/gpfsmon");
if(gpfsmonFile.is_open()){
gpfsmonFile << "io_s\n";
gpfsmonFile.close();
} else {
LOG(error) << "Gpfsmon: unable to create temporary file for mmpmon";
}
}
void Gpfsmon::readAsync() {
uint64_t now = getTimestamp();
read();
if (_timer != nullptr && _keepRunning) {
uint64_t next = now + MS_TO_NS(_interval);
_timer->expires_at(timestamp2ptime(next));
_timer->async_wait(std::bind(&Gpfsmon::readAsync, this));
}
}
void Gpfsmon::startPolling() {
_keepRunning = 1;
uint64_t waitToStart = starting_timestamp(_interval);
LOG(info) << "Sensor " << _name << " will be started in " << waitToStart / (1000*1000)<<"ms.";
_timer->expires_at(timestamp2ptime(waitToStart));
_timer->async_wait(std::bind(&Gpfsmon::readAsync, this));
LOG(info) << "Sensor " << _name << " started.";
}
void Gpfsmon::stopPolling() {
_keepRunning = 0;
//cancel any outstanding readAsync()
_timer->cancel();
LOG(info) << "Sensor " << _name << " stopped.";
}
void Gpfsmon::addMqttSuffixMetricToolID(std::string mqttSuffix, std::string metricName, uint64_t internalMetricId){
metric_internal_id miid;
if(internalMetricId <= IOData::Last && internalMetricId >= IOData::First){
miid.internalMetricId = static_cast<IOData::INTERNALMETRICID>(internalMetricId);
} else {
LOG(error) << "Gpfsmon toolId not recognized (out of bounds)=" << internalMetricId;
return;
}
miid.metric_name = metricName;
mqttSuffixToInternalId[mqttSuffix]=miid;
std::string mqttID = createIDFromMqttParts(_mqttPrefix, 0, mqttSuffix);
bool added = MultiSensor::addMqtt(mqttID);
if(!added){
LOG(error) << "Gpfsmon sensor unable to add MqttID=" << mqttID << " cpu=0, mqttMetricSuffix=" << mqttSuffix;
}
}
/*************************+ class IOData ***************************/
IOData::IOData() {
data[IOBYTESREAD]=0;
data[IOBYTESWRITE]=0;
data[IOOPENS]=0;
data[IOCLOSES]=0;
data[IOREADS]=0;
data[IOWRITES]=0;
}
IOData::~IOData() {
data.clear();
}
bool IOData::fillMemberData(char* line, int linenumber) {
std::string toparse(line);
//cout << toparse << endl;
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){
//cout << "token_substr = " << toparse.substr(bytereads_pos + 5, bytewrite_pos - bytereads_pos) << endl;
data[IOBYTESREAD] = std::stoull(toparse.substr(bytereads_pos + 5, bytewrite_pos - bytereads_pos));
//cout << "iobytesread = " << iobytesread << endl;
} else {
return false;
}
std::string::size_type opens_pos = toparse.find(" _oc_ ");
if( opens_pos != std::string::npos ){
//cout << "token_substr = " << toparse.substr(bytewrite_pos + 6, opens_pos - bytewrite_pos) << endl;
data[IOBYTESWRITE] = std::stoull(toparse.substr(bytewrite_pos + 6, opens_pos - bytewrite_pos));
//cout << "iobyteswrite = " << iobyteswrite << endl;
} else {
return false;
}
std::string::size_type closes_pos = toparse.find(" _cc_ ");
if( closes_pos != std::string::npos){
//cout << "token_substr = " << toparse.substr(opens_pos + 6, closes_pos - opens_pos) << endl;
data[IOOPENS] = std::stoull(toparse.substr(opens_pos + 6, closes_pos - opens_pos));
//cout << "ioopens = " << ioopens << endl;
} else {
return false;
}
std::string::size_type reads_pos = toparse.find(" _rdc_ ");
if( reads_pos != std::string::npos ){
//cout << "token_substr = " << toparse.substr(closes_pos + 6, reads_pos - closes_pos) << endl;
data[IOCLOSES] = std::stoull(toparse.substr(closes_pos + 6, reads_pos - closes_pos));
//cout << "iocloses = " << iocloses << endl;
} else {
return false;
}
std::string::size_type writes_pos = toparse.find(" _wc_ ");
if( writes_pos != std::string::npos ){
//cout << "token_substr = " << toparse.substr(reads_pos + 7, writes_pos - reads_pos) << endl;
data[IOREADS] = std::stoull(toparse.substr(reads_pos + 7, writes_pos - reads_pos));
//cout << "ioreads = " << ioreads << endl;
} else {
return false;
}
std::string::size_type dir_pos = toparse.find(" _dir_");
if( dir_pos != std::string::npos ){
//cout << "token_substr = " << toparse.substr(writes_pos + 6, dir_pos - writes_pos) << endl;
data[IOWRITES] = std::stoull(toparse.substr(writes_pos + 6, dir_pos - writes_pos));
//cout << "iowrites = " << iowrites << endl;
} else {
return false;
}
return true;
}
IOData operator-(IOData& lhs, IOData& rhs){
IOData result;
for (auto keyVal : result.data ) {
//result.data was constructed with zeros...
result.data[keyVal.first]=lhs.data[keyVal.first] - rhs.data[keyVal.first];
}
return result;
}
/*
* Gpfsmon.h
*
* Created on: 03.09.2018
* Author: lu43jih
*/
#ifndef SRC_SENSORS_GPFSMON_GPFSMON_H_
#define SRC_SENSORS_GPFSMON_GPFSMON_H_
#include "../../MultiSensor.h"
#include "../sensorutils/mqttutils.h"
#include "../sensorutils/timeutils.h"
/*! \class IOData
* \brief IO Data parser helper class
* \ingroup CommonMon
*/
class IOData {
public:
enum INTERNALMETRICID {
IOBYTESREAD=0,
IOBYTESWRITE=1,
IOOPENS=2,
IOCLOSES=3,
IOREADS=4,
IOWRITES=5,
First = IOBYTESREAD,
Last = IOWRITES
};
private:
std::map<INTERNALMETRICID, uint64_t> data;
public:
/** Constructor with default values
*
*/
IOData();
/** Destructor
*
*/
virtual ~IOData();
/** Fill member data by parsing line.
*
* @param[in] line char string to be parsed
* @param[in] linenumber line number that is being parsed
* @return true if successful.
*/
bool fillMemberData(char *line, int linenumber);
friend IOData operator-(IOData& lhs, IOData& rhs);
uint64_t getMetric(INTERNALMETRICID metricId){
return data[metricId];
}
};
IOData operator-(IOData& lhs, IOData& rhs);
class Gpfsmon: public MultiSensor {
private:
struct metric_internal_id {
std::string metric_name;
IOData::INTERNALMETRICID internalMetricId;
};
std::map<std::string, metric_internal_id> mqttSuffixToInternalId;
std::string _mqttPrefix;
std::vector<std::unique_ptr<IOData>> _beforeIOData;
std::vector<std::unique_ptr<IOData>> _afterIOData;
public:
Gpfsmon(const std::string& name, std::string& mqttPrefix);
Gpfsmon()=delete;
virtual ~Gpfsmon();
void createTempFile();
virtual void read() override;
virtual void readAsync() override;
virtual void startPolling() override;
virtual void stopPolling() override;
void pushReading(std::string & mqttSuffix, reading_t& reading, uint64_t (*getter)() );
void addMqttSuffixMetricToolID(std::string mqttSuffix, std::string metricName, uint64_t toolId);
};
#endif /* SRC_SENSORS_GPFSMON_GPFSMON_H_ */
/*
* GpfsmonConfigurator.cpp
*
* Created on: 03.09.2018
* Author: lu43jih
*/
#include "GpfsmonConfigurator.h"
#include <boost/foreach.hpp>
#include <boost/property_tree/info_parser.hpp>
#include <boost/algorithm/string.hpp>
#include "Gpfsmon.h"
#include "../sensorutils/utilities.h"
GpfsmonConfigurator::GpfsmonConfigurator() {
}
GpfsmonConfigurator::~GpfsmonConfigurator() {
}
bool GpfsmonConfigurator::readConfig(std::string cfgPath) {
boost::property_tree::iptree cfg;
boost::property_tree::read_info(cfgPath, cfg);
//read global variables (if present overwrite those from global.conf)
//currently only overwriting of mqttPrefix is supported
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();
LOG(debug) << " Using own MQTT-Prefix " << _mqttPrefix;
} else {
LOG(warning) << " Value \"" << global.first << "\" not recognized. Omitting...";
}
}
}
//read one sensor at a time
BOOST_FOREACH(boost::property_tree::iptree::value_type &sensor, cfg.get_child("sensors")) {
if (boost::iequals(sensor.first, "sensor")) {
LOG(debug) << "Sensor \"" << sensor.second.data() << "\"";
if (!sensor.second.empty()) {
auto gpfsmon = make_unique<Gpfsmon>(sensor.second.data(), _mqttPrefix);
//read remaining values
if(readSensor(gpfsmon, sensor.second)){
_multiSensors.push_back(std::move(gpfsmon));
}
}
}
}
return true;
}
bool GpfsmonConfigurator::readSensor(std::unique_ptr<Gpfsmon>& sensor, boost::property_tree::iptree& config) {
std::string unparsedMetricList;
std::string idlistfile;
BOOST_FOREACH(boost::property_tree::iptree::value_type &s, config) {
if (boost::iequals(s.first, "interval")) {
sensor->setInterval(std::stoull(s.second.data()));
} else if (boost::iequals(s.first, "minValues")) {
sensor->setMinValues(std::stoull(s.second.data()));
} else if (boost::iequals(s.first, "metricList")) {
unparsedMetricList = s.second.data();
} else if (boost::iequals(s.first, "idListFile")) {
idlistfile = s.second.data();
} else {
LOG(warning) << " Value \"" << s.first << "\" not recognized. Omitting...";
}
}
std::map<mqtt_id_t, metric_internalid> mqttToIds;
try {
getMqttToIds(mqttToIds,unparsedMetricList, idlistfile);
} catch(const std::ifstream::failure& e) {
LOG(error) << "GpfsmonConfigurator: Exception in getMqttToIds=" << e.what();
}
for(auto &mqttS_Ids : mqttToIds){
sensor->addMqttSuffixMetricToolID(mqttS_Ids.first, mqttS_Ids.second.metric_name, mqttS_Ids.second.internalid);
}
//sarms->addMqtt(_mqttPrefix);
LOG(debug) << " Name : " << sensor->getName();
LOG(debug) << " Interval: " << sensor->getInterval();
LOG(debug) << " minValues:" << sensor->getMinValues();
return true;
}
/*
* GpfsmonConfigurator.h
*
* Created on: 03.09.2018
* Author: lu43jih
*/
#ifndef SRC_SENSORS_GPFSMON_GPFSMONCONFIGURATOR_H_
#define SRC_SENSORS_GPFSMON_GPFSMONCONFIGURATOR_H_
#include <boost/property_tree/ptree_fwd.hpp>
#include <string>
#include "../../Configurator.h"
#include "Gpfsmon.h"
class GpfsmonConfigurator : public Configurator{
public:
GpfsmonConfigurator();
virtual ~GpfsmonConfigurator();
/**
* Read the configuration for perfpusher.
* @param cfgPath Path + name of the configuration file
* @return true on success, false otherwise
*/
bool readConfig(std::string cfgPath) override;
/**
* 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
*/
bool readSensor(std::unique_ptr<Gpfsmon> &sensor, boost::property_tree::iptree& config);
};
extern "C" Configurator* create() {
return new GpfsmonConfigurator;
}
extern "C" void destroy(Configurator* c) {
delete c;
}
#endif /* SRC_SENSORS_GPFSMON_GPFSMONCONFIGURATOR_H_ */
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