Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
dcdb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
7
Issues
7
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
dcdb
dcdb
Commits
0418db48
Commit
0418db48
authored
Feb 22, 2019
by
Micha Müller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MSR: duplication of sensors for each cpu is now done in the Configurator
parent
9d77eae5
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
190 additions
and
38 deletions
+190
-38
src/includes/ConfiguratorTemplate.h
src/includes/ConfiguratorTemplate.h
+1
-2
src/sensors/msr/MSRConfigurator.cpp
src/sensors/msr/MSRConfigurator.cpp
+164
-1
src/sensors/msr/MSRConfigurator.h
src/sensors/msr/MSRConfigurator.h
+12
-1
src/sensors/msr/MSRSensorBase.h
src/sensors/msr/MSRSensorBase.h
+1
-1
src/sensors/msr/MSRSensorGroup.cpp
src/sensors/msr/MSRSensorGroup.cpp
+9
-31
src/sensors/msr/MSRSensorGroup.h
src/sensors/msr/MSRSensorGroup.h
+3
-2
No files found.
src/includes/ConfiguratorTemplate.h
View file @
0418db48
...
...
@@ -383,8 +383,7 @@ protected:
if
(
!
isTemplate
)
{
boost
::
optional
<
boost
::
property_tree
::
iptree
&>
def
=
config
.
get_child_optional
(
"default"
);
if
(
def
)
{
//we copy all values from default (including copy constructing its sensors)
//if own sensors are specified they are appended
//we copy all values from default
LOG
(
debug
)
<<
" Using
\"
"
<<
def
.
get
().
data
()
<<
"
\"
as default."
;
auto
it
=
_templateSensorBases
.
find
(
def
.
get
().
data
());
if
(
it
!=
_templateSensorBases
.
end
())
{
...
...
src/sensors/msr/MSRConfigurator.cpp
View file @
0418db48
...
...
@@ -2,7 +2,7 @@
* MSRConfigurator.cpp
*
* Created on: 28.01.2019
* Author:
Your name goes here!
* Author:
Carla Guillen
*/
#include "MSRConfigurator.h"
...
...
@@ -33,3 +33,166 @@ void MSRConfigurator::sensorGroup(MSRSensorGroup& s, CFG_VAL config) {
}
}
/**
* Custom readConfig, as MSR has to copy sensors for each CPU
*/
bool
MSRConfigurator
::
readConfig
(
std
::
string
cfgPath
)
{
_cfgPath
=
cfgPath
;
boost
::
property_tree
::
iptree
cfg
;
boost
::
property_tree
::
read_info
(
cfgPath
,
cfg
);
//read global variables (if present overwrite those from global.conf)
readGlobal
(
cfg
);
//read groups and templates for groups
BOOST_FOREACH
(
boost
::
property_tree
::
iptree
::
value_type
&
val
,
cfg
)
{
//template group
if
(
boost
::
iequals
(
val
.
first
,
"template_"
+
_groupName
))
{
LOG
(
debug
)
<<
"Template "
<<
_groupName
<<
"
\"
"
<<
val
.
second
.
data
()
<<
"
\"
"
;
if
(
!
val
.
second
.
empty
())
{
MSRSensorGroup
*
group
=
new
MSRSensorGroup
(
val
.
second
.
data
());
if
(
readSensorGroup
(
*
group
,
val
.
second
,
true
))
{
auto
ret
=
_templateSensorGroups
.
insert
(
std
::
pair
<
std
::
string
,
MSRSensorGroup
*>
(
val
.
second
.
data
(),
group
));
if
(
!
ret
.
second
)
{
LOG
(
warning
)
<<
"Template "
<<
_groupName
<<
" "
<<
val
.
second
.
data
()
<<
" already exists! Omitting..."
;
delete
group
;
}
}
else
{
LOG
(
warning
)
<<
"Template "
<<
_groupName
<<
"
\"
"
<<
val
.
second
.
data
()
<<
"
\"
has bad values! Ignoring..."
;
delete
group
;
}
}
//template base
}
else
if
(
boost
::
iequals
(
val
.
first
,
"template_"
+
_baseName
))
{
LOG
(
debug
)
<<
"Template "
<<
_baseName
<<
"
\"
"
<<
val
.
second
.
data
()
<<
"
\"
"
;
if
(
!
val
.
second
.
empty
())
{
MSRSensorBase
*
base
=
new
MSRSensorBase
(
val
.
second
.
data
());
if
(
readSensorBase
(
*
base
,
val
.
second
,
true
))
{
auto
ret
=
_templateSensorBases
.
insert
(
std
::
pair
<
std
::
string
,
MSRSensorBase
*>
(
val
.
second
.
data
(),
base
));
if
(
!
ret
.
second
)
{
LOG
(
warning
)
<<
"Template "
<<
_baseName
<<
" "
<<
val
.
second
.
data
()
<<
" already exists! Omitting..."
;
delete
base
;
}
}
else
{
LOG
(
warning
)
<<
"Template "
<<
_baseName
<<
"
\"
"
<<
val
.
second
.
data
()
<<
"
\"
has bad values! Ignoring..."
;
delete
base
;
}
}
//template single sensor
}
else
if
(
boost
::
iequals
(
val
.
first
,
"template_single_"
+
_baseName
))
{
LOG
(
debug
)
<<
"Template single "
<<
_baseName
<<
"
\"
"
<<
val
.
second
.
data
()
<<
"
\"
"
;
if
(
!
val
.
second
.
empty
())
{
MSRSensorGroup
*
group
=
new
MSRSensorGroup
(
val
.
second
.
data
());
if
(
readSensorGroup
(
*
group
,
val
.
second
,
true
))
{
//group which consists of only one sensor
SB_Ptr
sensor
=
std
::
make_shared
<
MSRSensorBase
>
(
val
.
second
.
data
());
if
(
readSensorBase
(
*
sensor
,
val
.
second
,
true
))
{
group
->
pushBackSensor
(
sensor
);
auto
ret
=
_templateSensorGroups
.
insert
(
std
::
pair
<
std
::
string
,
MSRSensorGroup
*>
(
val
.
second
.
data
(),
group
));
if
(
!
ret
.
second
)
{
LOG
(
warning
)
<<
"Template single "
<<
_baseName
<<
" "
<<
val
.
second
.
data
()
<<
" already exists! Omitting..."
;
delete
group
;
}
}
else
{
LOG
(
warning
)
<<
"Template single "
<<
_baseName
<<
" "
<<
val
.
second
.
data
()
<<
" could not be read! Omitting"
;
delete
group
;
}
}
else
{
LOG
(
warning
)
<<
"Template single "
<<
_baseName
<<
"
\"
"
<<
val
.
second
.
data
()
<<
"
\"
has bad values! Ignoring..."
;
delete
group
;
}
}
//group
}
else
if
(
boost
::
iequals
(
val
.
first
,
_groupName
))
{
LOG
(
debug
)
<<
_groupName
<<
"
\"
"
<<
val
.
second
.
data
()
<<
"
\"
"
;
if
(
!
val
.
second
.
empty
())
{
SG_Ptr
group
=
std
::
make_shared
<
MSRSensorGroup
>
(
val
.
second
.
data
());
if
(
readSensorGroup
(
*
group
,
val
.
second
))
{
customizeAndStore
(
group
);
}
else
{
LOG
(
warning
)
<<
_groupName
<<
"
\"
"
<<
val
.
second
.
data
()
<<
"
\"
has bad values! Ignoring..."
;
}
}
//single sensor
}
else
if
(
boost
::
iequals
(
val
.
first
,
"single_"
+
_baseName
))
{
LOG
(
debug
)
<<
"Single "
<<
_baseName
<<
"
\"
"
<<
val
.
second
.
data
()
<<
"
\"
"
;
if
(
!
val
.
second
.
empty
())
{
SG_Ptr
group
=
std
::
make_shared
<
MSRSensorGroup
>
(
val
.
second
.
data
());
if
(
readSensorGroup
(
*
group
,
val
.
second
))
{
//group which consists of only one sensor
SB_Ptr
sensor
;
//perhaps one sensor is already present because it was copied from the template group
if
(
group
->
getSensors
().
size
()
!=
0
)
{
sensor
=
std
::
dynamic_pointer_cast
<
MSRSensorBase
>
(
group
->
getSensors
()[
0
]);
//check if cast was successful (sensor != nullptr)
if
(
sensor
)
{
sensor
->
setName
(
val
.
second
.
data
());
if
(
readSensorBase
(
*
sensor
,
val
.
second
))
{
customizeAndStore
(
group
);
}
else
{
LOG
(
warning
)
<<
"Single "
<<
_baseName
<<
" "
<<
val
.
second
.
data
()
<<
" could not be read! Omitting"
;
}
}
else
{
LOG
(
warning
)
<<
"Single "
<<
_baseName
<<
" "
<<
val
.
second
.
data
()
<<
" had a type mismatch when casting! Omitting"
;
}
}
else
{
sensor
=
std
::
make_shared
<
MSRSensorBase
>
(
val
.
second
.
data
());
if
(
readSensorBase
(
*
sensor
,
val
.
second
))
{
group
->
pushBackSensor
(
sensor
);
customizeAndStore
(
group
);
}
else
{
LOG
(
warning
)
<<
"Single "
<<
_baseName
<<
" "
<<
val
.
second
.
data
()
<<
" could not be read! Omitting"
;
}
}
}
else
{
LOG
(
warning
)
<<
"Single "
<<
_baseName
<<
"
\"
"
<<
val
.
second
.
data
()
<<
"
\"
has bad values! Ignoring..."
;
}
}
}
else
if
(
!
boost
::
iequals
(
val
.
first
,
"global"
)
)
{
LOG
(
error
)
<<
"
\"
"
<<
val
.
first
<<
"
\"
: unknown construct!"
;
return
false
;
}
}
//read of config finished. Now we build the mqtt-topic for every sensor
constructSensorNames
();
for
(
const
auto
&
g
:
_sensorGroups
)
{
for
(
const
auto
&
s
:
g
->
getSensors
())
{
s
->
setMqtt
(
_mqttPrefix
+
g
->
getMqttPart
()
+
s
->
getMqtt
());
LOG
(
debug
)
<<
g
->
getGroupName
()
<<
"::"
<<
s
->
getName
()
<<
" using MQTT-topic
\"
"
<<
s
->
getMqtt
()
<<
"
\"
"
;
}
}
return
true
;
}
void
MSRConfigurator
::
customizeAndStore
(
SG_Ptr
g
)
{
bool
begin
=
true
;
std
::
vector
<
SB_Ptr
>
original
;
for
(
auto
cpu
:
g
->
getCpus
())
{
if
(
begin
){
for
(
auto
s
:
g
->
getSensors
())
{
SB_Ptr
sensor
=
std
::
dynamic_pointer_cast
<
MSRSensorBase
>
(
s
);
sensor
->
setCpu
(
cpu
);
s
->
setName
(
s
->
getName
(),
cpu
);
auto
size
=
s
->
getMqtt
().
size
();
s
->
setMqtt
(
formatMqttCPU
(
"XX"
,
cpu
)
+
s
->
getMqtt
().
substr
(
size
-
2
));
original
.
push_back
(
sensor
);
}
begin
=
false
;
}
else
{
for
(
auto
s
:
original
)
{
auto
s_otherCPUs
=
std
::
make_shared
<
MSRSensorBase
>
(
s
->
getName
());
s_otherCPUs
->
setName
(
s
->
getName
(),
cpu
);
s_otherCPUs
->
setCpu
(
cpu
);
s_otherCPUs
->
setMetric
(
s
->
getMetric
());
auto
size
=
s
->
getMqtt
().
size
();
s_otherCPUs
->
setMqtt
(
formatMqttCPU
(
"XX"
,
cpu
)
+
s
->
getMqtt
().
substr
(
size
-
2
));
g
->
pushBackSensor
(
s_otherCPUs
);
}
}
}
storeSensorGroup
(
g
);
}
src/sensors/msr/MSRConfigurator.h
View file @
0418db48
...
...
@@ -2,7 +2,7 @@
* MSRConfigurator.h
*
* Created on: 28.01.2019
* Author:
Your name goes here!
* Author:
Carla Guillen
*/
#ifndef MSR_MSRCONFIGURATOR_H_
...
...
@@ -21,6 +21,17 @@ protected:
/* Overwritten from ConfiguratorTemplate */
void
sensorBase
(
MSRSensorBase
&
s
,
CFG_VAL
config
)
override
;
void
sensorGroup
(
MSRSensorGroup
&
s
,
CFG_VAL
config
)
override
;
bool
readConfig
(
std
::
string
cfgPath
)
override
;
private:
/**
* Takes a MSRSensorGroup and duplicates its sensors for every CPU.
* Assigns one CPU value to every newly constructed sensor and stores the
* group afterwards.
*
* @param g MSRSensorGroup which is to be customized for every CPU
*/
void
customizeAndStore
(
SG_Ptr
g
);
};
extern
"C"
ConfiguratorInterface
*
create
()
{
...
...
src/sensors/msr/MSRSensorBase.h
View file @
0418db48
...
...
@@ -2,7 +2,7 @@
* MSRSensorBase.h
*
* Created on: 28.01.2019
* Author:
Your name goes here!
* Author:
Carla Guillen
*/
#ifndef MSR_MSRSENSORBASE_H_
...
...
src/sensors/msr/MSRSensorGroup.cpp
View file @
0418db48
...
...
@@ -2,7 +2,7 @@
* MSRSensorGroup.cpp
*
* Created on: 28.01.2019
* Author:
Your name goes here!
* Author:
Carla Guillen
*/
#include "MSRSensorGroup.h"
...
...
@@ -35,36 +35,6 @@ MSRSensorGroup::MSRSensorGroup(const std::string& name) :
MSRSensorGroup
::~
MSRSensorGroup
()
{
}
/*void MSRSensorGroup::init(boost::asio::io_service& io) {
SensorGroupTemplate::init(io);
bool begin = true;
std::vector<S_Ptr> original;
for(auto &kv: cpuToFd){
if (begin){
for(auto s : _sensors) {
s->setCpu(kv.first);
s->setName(s->getName(),kv.first);
std::stringstream ss;
auto size = s->getMqtt().size();
ss << _mqttPrefix << std::setw(2) << std::setfill('0') << kv.first << s->getMqtt().substr(size-2);
std::string mqtt = ss.str();
s->setMqtt(mqtt);
original.push_back(s);
}
begin = false;
} else {
for (auto s: original) {
auto s_otherCPUs = std::make_shared<MSRSensorBase>(s->getName());
s_otherCPUs->setName(s->getName(), kv.first);
s_otherCPUs->setCpu(kv.first);
s_otherCPUs->setMetric(s->getMetric());
pushBackSensor(s_otherCPUs);
}
}
}
}*/
void
MSRSensorGroup
::
start
()
{
if
(
_keepRunning
)
{
//we have been started already
...
...
@@ -185,6 +155,14 @@ void MSRSensorGroup::addCpu(unsigned int cpu){
cpuToFd
[
cpu
]
=
-
1
;
/* -1 because no file descriptor has been assigned yet. */
}
std
::
vector
<
unsigned
>
MSRSensorGroup
::
getCpus
()
{
std
::
vector
<
unsigned
>
cpus
;
for
(
auto
kv
:
cpuToFd
)
{
cpus
.
push_back
(
kv
.
first
);
}
return
cpus
;
}
void
MSRSensorGroup
::
printConfig
(
LOG_LEVEL
ll
)
{
std
::
stringstream
ss
;
const
char
*
separator
=
""
;
...
...
src/sensors/msr/MSRSensorGroup.h
View file @
0418db48
...
...
@@ -2,7 +2,7 @@
* MSRSensorGroup.h
*
* Created on: 28.01.2019
* Author:
Your name goes here!
* Author:
Carla Guillen
*/
#ifndef MSR_MSRSENSORGROUP_H_
...
...
@@ -11,6 +11,7 @@
#include "../../includes/SensorGroupTemplate.h"
#include <map>
#include <vector>
#include <string>
#include <cstdint>
...
...
@@ -26,7 +27,7 @@ public:
void
start
()
override
;
void
stop
()
override
;
void
addCpu
(
unsigned
int
cpu
);
//void init(boost::asio::io_service& io) override
;
std
::
vector
<
unsigned
>
getCpus
()
;
void
printConfig
(
LOG_LEVEL
ll
)
override
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment