Commit 78ee6cd6 authored by Micha Mueller's avatar Micha Mueller
Browse files

Add prototypical plugin for receiving caliper data

parent 06805839
......@@ -42,7 +42,7 @@ else
BACNET_PORT = linux
LIBEXT = so
LIBFLAGS = -shared -Wl,-soname,
PLUGINS+= perfevent
PLUGINS+= perfevent caliper
PLUGINFLAGS = -fPIC
endif
PLUGIN_LIBS = $(foreach p,$(PLUGINS),libdcdbplugin_$(p).$(LIBEXT))
......@@ -106,3 +106,6 @@ libdcdbplugin_gpfsmon.$(LIBEXT): sensors/gpfsmon/GpfsmonSensorGroup.o sensors/gp
#libdcdbplugin_opa.$(LIBEXT): sensors/opa/OpaSensorGroup.o sensors/opa/OpaConfigurator.o
# $(CXX) $(LIBFLAGS)$@ -o $@ $^ -L$(DCDBDEPLOYPATH)/lib/ -lboost_log -lboost_system -lboost_regex -lopamgt -libverbs -libumad -lssl
libdcdbplugin_caliper.$(LIBEXT): sensors/caliper/CaliperSensorGroup.o sensors/caliper/CaliperConfigurator.o
$(CXX) $(LIBFLAGS)$@ -o $@ $^ -L$(DCDBDEPLOYPATH)/lib/ -lboost_log -lboost_system
\ No newline at end of file
global {
mqttPrefix /FF112233445566778899AABB
}
group cali {
interval 100
mqttprefix 01
}
//================================================================================
// Name : CaliperConfigurator.cpp
// Author : Micha Mueller
// Copyright : Leibniz Supercomputing Centre
// Description : Source file for Caliper plugin configurator class.
//================================================================================
//================================================================================
// This file is part of DCDB (DataCenter DataBase)
// Copyright (C) 2019-2019 Leibniz Supercomputing Centre
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//================================================================================
#include "CaliperConfigurator.h"
CaliperConfigurator::CaliperConfigurator() {
_groupName = "group";
_baseName = "sensor";
}
CaliperConfigurator::~CaliperConfigurator() {}
void CaliperConfigurator::sensorBase(CaliperSensorBase& s, CFG_VAL config) {
ADD {
//no sensor attributes currently
}
}
void CaliperConfigurator::sensorGroup(CaliperSensorGroup& s, CFG_VAL config) {
ADD {
//no group attributes currently
}
}
//================================================================================
// Name : CaliperConfigurator.h
// Author : Micha Mueller
// Copyright : Leibniz Supercomputing Centre
// Description : Header file for Caliper plugin configurator class.
//================================================================================
//================================================================================
// This file is part of DCDB (DataCenter DataBase)
// Copyright (C) 2019-2019 Leibniz Supercomputing Centre
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//================================================================================
#ifndef CALIPER_CALIPERCONFIGURATOR_H_
#define CALIPER_CALIPERCONFIGURATOR_H_
#include "../../includes/ConfiguratorTemplate.h"
#include "CaliperSensorGroup.h"
/**
* @brief ConfiguratorTemplate specialization for this plugin.
*
* @ingroup cali
*/
class CaliperConfigurator : public ConfiguratorTemplate<CaliperSensorBase, CaliperSensorGroup> {
public:
CaliperConfigurator();
virtual ~CaliperConfigurator();
protected:
/* Overwritten from ConfiguratorTemplate */
void sensorBase(CaliperSensorBase& s, CFG_VAL config) override;
void sensorGroup(CaliperSensorGroup& s, CFG_VAL config) override;
};
extern "C" ConfiguratorInterface* create() {
return new CaliperConfigurator;
}
extern "C" void destroy(ConfiguratorInterface* c) {
delete c;
}
#endif /* CALIPER_CALIPERCONFIGURATOR_H_ */
//================================================================================
// Name : CaliperSensorBase.h
// Author : Micha Mueller
// Copyright : Leibniz Supercomputing Centre
// Description : Sensor base class for Caliper plugin.
//================================================================================
//================================================================================
// This file is part of DCDB (DataCenter DataBase)
// Copyright (C) 2019-2019 Leibniz Supercomputing Centre
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//================================================================================
/**
* @defgroup cali Caliper plugin
* @ingroup pusherplugins
*
* @brief Listen for data sent by Caliper framework.
*/
#ifndef CALIPER_CALIPERSENSORBASE_H_
#define CALIPER_CALIPERSENSORBASE_H_
#include "sensorbase.h"
/*
* TODO
* Add plugin specific includes
*/
/**
* @brief SensorBase specialization for this plugin.
*
* @ingroup cali
*/
class CaliperSensorBase : public SensorBase {
public:
CaliperSensorBase(const std::string& name) :
SensorBase(name) {
/*
* TODO
* Initialize plugin specific attributes
*/
}
CaliperSensorBase(const CaliperSensorBase& other) :
SensorBase(other) {
/*
* TODO
* Copy construct plugin specific attributes
*/
}
virtual ~CaliperSensorBase() {
/*
* TODO
* If necessary, deconstruct plugin specific attributes
*/
}
CaliperSensorBase& operator=(const CaliperSensorBase& other) {
SensorBase::operator=(other);
/*
* TODO
* Implement assignment operator for plugin specific attributes
*/
return *this;
}
/*
* TODO
* Getters and Setters for plugin specific attributes
*/
void printConfig(LOG_LEVEL ll, LOGGER& lg) {
/*
* TODO
* Log attributes here for debug reasons
*/
LOG_VAR(ll) << " NumSpacesAsIndention: " << 5;
}
protected:
/*
* TODO
* Add plugin specific attributes here
*/
};
#endif /* CALIPER_CALIPERSENSORBASE_H_ */
//================================================================================
// Name : CaliperSensorGroup.cpp
// Author : Micha Mueller
// Copyright : Leibniz Supercomputing Centre
// Description : Source file for Caliper sensor group class.
//================================================================================
//================================================================================
// This file is part of DCDB (DataCenter DataBase)
// Copyright (C) 2019-2019 Leibniz Supercomputing Centre
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//================================================================================
#include "CaliperSensorGroup.h"
#include <errno.h>
#include <stdio.h>
#include <sys/socket.h>
#include "timestamp.h"
CaliperSensorGroup::CaliperSensorGroup(const std::string& name) :
SensorGroupTemplate(name),
_socket(-1),
_connection(-1) {
}
CaliperSensorGroup::CaliperSensorGroup(const CaliperSensorGroup& other) :
SensorGroupTemplate(other),
_socket(-1),
_connection(-1) {
}
CaliperSensorGroup::~CaliperSensorGroup() {
if(_keepRunning) {
stop();
}
}
CaliperSensorGroup& CaliperSensorGroup::operator=(const CaliperSensorGroup& other) {
SensorGroupTemplate::operator=(other);
_socket = -1;
_connection = -1;
return *this;
}
void CaliperSensorGroup::start() {
if (_keepRunning) {
//we have been started already
LOG(info) << "Sensorgroup " << _groupName << " already running.";
return;
}
_socket = socket(AF_UNIX, SOCK_SEQPACKET | SOCK_NONBLOCK, 0);
if(_socket == -1) {
LOG(error) << _groupName << ": Failed to open socket:" << strerror(errno);
return;
}
sockaddr_un addr;
memset(&addr, 0, sizeof(struct sockaddr_un));
addr.sun_family = AF_UNIX;
snprintf(&addr.sun_path[1], 91, "DCDBPusherCaliSocket");
if(bind(_socket, (struct sockaddr*) &addr, sizeof(addr))) {
LOG(error) << _groupName << ": Failed to bind socket:" << strerror(errno);
close(_socket);
_socket = -1;
return;
}
if(listen(_socket, 1)) {
LOG(error) << _groupName << ": Can not listen on socket:" << strerror(errno);
close(_socket);
_socket = -1;
return;
}
_keepRunning = 1;
_pendingTasks++;
_timer->async_wait(std::bind(&CaliperSensorGroup::readAsync, this));
LOG(info) << "Sensorgroup " << _groupName << " started.";
}
void CaliperSensorGroup::stop() {
_keepRunning = 0;
//wait before closing _file
wait();
if(_connection != -1) {
close(_connection);
_connection = -1;
}
if(_socket != -1) {
close(_socket);
_socket = -1;
}
LOG(info) << "Sensorgroup " << _groupName << " stopped.";
}
void CaliperSensorGroup::read() {
if (_connection == -1) {
_connection = accept(_socket, NULL, NULL);
if (_connection == -1) {
if (errno != EAGAIN && errno != EWOULDBLOCK) {
LOG(error) << _groupName << ": Accept failed:" << strerror(errno);
}
return;
}
}
const size_t bufSize = 2048;
char buf[bufSize];
const ssize_t nrec = recv(_connection, (void *) buf, bufSize, MSG_DONTWAIT);
if (nrec == 0) {
close(_connection);
_connection = -1;
return;
} else if (nrec == -1) {
if (errno != EAGAIN && errno != EWOULDBLOCK) {
LOG(error) << _groupName << ": Recv failed: " << strerror(errno);
}
return;
} else {
std::string timestamp(buf);
std::string function(&(buf[timestamp.length()+1]));
LOG(info) << _groupName << ": Received value " << function << " (" << timestamp << ")";
}
/* reading_t reading;
reading.timestamp = getTimestamp();
try {
for(auto s : _sensors) {
reading.value = *
* TODO
* Read a value for every sensor affiliated with this group and store
* it with the appropriate sensor.
* 0;
s->storeReading(reading);
#ifdef DEBUG
LOG(debug) << _groupName << "::" << s->getName() << " raw reading: \"" << reading.value << "\"";
#endif
}
} catch (const std::exception& e) {
LOG(error) << "Sensorgroup" << _groupName << " could not read value: " << e.what();
}*/
}
void CaliperSensorGroup::readAsync() {
uint64_t now = getTimestamp();
read();
if (_timer && _keepRunning) {
_timer->expires_at(timestamp2ptime(nextReadingTime()));
_pendingTasks++;
_timer->async_wait(std::bind(&CaliperSensorGroup::readAsync, this));
}
_pendingTasks--;
}
void CaliperSensorGroup::printConfig(LOG_LEVEL ll) {
}
//================================================================================
// Name : CaliperSensorGroup.h
// Author : Micha Mueller
// Copyright : Leibniz Supercomputing Centre
// Description : Header file for Caliper sensor group class.
//================================================================================
//================================================================================
// This file is part of DCDB (DataCenter DataBase)
// Copyright (C) 2019-2019 Leibniz Supercomputing Centre
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//================================================================================
#ifndef CALIPER_CALIPERSENSORGROUP_H_
#define CALIPER_CALIPERSENSORGROUP_H_
#include "../../includes/SensorGroupTemplate.h"
#include "CaliperSensorBase.h"
/**
* @brief SensorGroupTemplate specialization for this plugin.
*
* @ingroup caliper
*/
class CaliperSensorGroup : public SensorGroupTemplate<CaliperSensorBase> {
public:
CaliperSensorGroup(const std::string& name);
CaliperSensorGroup(const CaliperSensorGroup& other);
virtual ~CaliperSensorGroup();
CaliperSensorGroup& operator=(const CaliperSensorGroup& other);
void start() override;
void stop() override;
void printConfig(LOG_LEVEL ll) override;
private:
void read() override;
void readAsync() override;
int _socket;
int _connection;
};
#endif /* CALIPER_CALIPERSENSORGROUP_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