Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
9.2.2023: Due to updates GitLab will be unavailable for some minutes between 9:00 and 11:00.
Open sidebar
dcdb
dcdb
Commits
73a85f92
Commit
73a85f92
authored
Nov 24, 2018
by
Micha Mueller
Browse files
Adapt all plugins for std::shared_ptrs
parent
294e1751
Changes
17
Hide whitespace changes
Inline
Side-by-side
src/sensors/bacnet/BACnetSensorGroup.cpp
View file @
73a85f92
...
...
@@ -23,7 +23,7 @@ void BACnetSensorGroup::init(boost::asio::io_service& io) {
#ifdef DEBUG
LOG
(
debug
)
<<
" DeviceInstance: "
<<
_deviceInstance
;
LOG
(
debug
)
<<
" "
<<
_sensors
.
size
()
<<
" Sensors:"
;
for
(
auto
s
:
_sensors
)
{
for
(
const
auto
&
s
:
_sensors
)
{
LOG
(
debug
)
<<
" "
<<
s
->
getName
();
LOG
(
debug
)
<<
" ObjectInstance: "
<<
s
->
getObjectInstance
();
LOG
(
debug
)
<<
" ObjectType: "
<<
s
->
getObjectType
();
...
...
@@ -64,7 +64,7 @@ void BACnetSensorGroup::read() {
reading_t
reading
;
reading
.
timestamp
=
getTimestamp
();
for
(
auto
s
:
_sensors
)
{
for
(
const
auto
&
s
:
_sensors
)
{
try
{
reading
.
value
=
_bacClient
->
readProperty
(
getDeviceInstance
(),
s
->
getObjectInstance
(),
s
->
getObjectType
(),
s
->
getPropertyId
())
*
s
->
getFactor
();
#ifdef DEBUG
...
...
src/sensors/ipmi/IPMIHost.h
View file @
73a85f92
...
...
@@ -19,8 +19,8 @@ public:
IPMIHost
();
virtual
~
IPMIHost
();
/* Translate recordId to SDR record */
bool
getSdrRecord
(
uint16_t
recordId
,
std
::
vector
<
uint8_t
>&
record
);
/* Translate recordId to SDR record */
bool
getSdrRecord
(
uint16_t
recordId
,
std
::
vector
<
uint8_t
>&
record
);
/* Send raw command to BMC. Returns sensor reading as responded by BMC. */
uint64_t
sendRawCmd
(
const
std
::
vector
<
uint8_t
>&
rawCmd
,
uint16_t
start
,
uint16_t
stop
);
/* Read the sensor specified by its record id. Returns sensor reading. */
...
...
src/sensors/ipmi/IPMISensorGroup.cpp
View file @
73a85f92
...
...
@@ -63,7 +63,7 @@ void IPMISensorGroup::read() {
reading_t
reading
;
reading
.
timestamp
=
getTimestamp
();
for
(
auto
s
:
_sensors
)
{
for
(
const
auto
&
s
:
_sensors
)
{
try
{
if
(
s
->
getRecordId
()
!=
0
)
{
/* recordId was set */
std
::
vector
<
uint8_t
>
sdrRecord
=
s
->
getSdrRecord
();
...
...
src/sensors/opa/OpaSensorGroup.cpp
View file @
73a85f92
...
...
@@ -72,7 +72,7 @@ void OpaSensorGroup::read() {
return
;
}
for
(
auto
s
:
_sensors
)
{
for
(
const
auto
&
s
:
_sensors
)
{
switch
(
s
->
getCounterData
())
{
case
(
portXmitData
)
:
reading
.
value
=
portCounters
.
portXmitData
;
...
...
src/sensors/pdu/PDUSensorGroup.cpp
View file @
73a85f92
...
...
@@ -75,7 +75,7 @@ void PDUSensorGroup::read() {
reading_t
reading
;
reading
.
timestamp
=
getTimestamp
();
for
(
auto
s
:
_sensors
)
{
for
(
const
auto
&
s
:
_sensors
)
{
try
{
std
::
string
readStr
;
const
xmlPathVector_t
&
xmlPath
=
s
->
getXMLPath
();
...
...
src/sensors/perfevent/PerfSensorBase.h
View file @
73a85f92
...
...
@@ -45,4 +45,6 @@ protected:
unsigned
int
_config
;
};
using
PerfSBPtr
=
std
::
shared_ptr
<
PerfSensorBase
>
;
#endif
/* PERFEVENT_PERFSENSORBASE_H_ */
src/sensors/perfevent/PerfSensorGroup.cpp
View file @
73a85f92
...
...
@@ -90,7 +90,7 @@ void PerfSensorGroup::start() {
//open perf-counters
struct
perf_event_attr
pe
;
PerfS
ensorBase
*
pc
=
_sensors
[
0
];
PerfS
BPtr
pc
=
_sensors
[
0
];
memset
(
&
pe
,
0
,
sizeof
(
struct
perf_event_attr
));
pe
.
size
=
sizeof
(
struct
perf_event_attr
);
...
...
@@ -222,7 +222,7 @@ void PerfSensorGroup::read() {
void
PerfSensorGroup
::
readAsync
()
{
read
();
if
(
_sensorGroupLeader
)
{
for
(
auto
g
:
_fellowSensorGroups
)
{
for
(
const
auto
&
g
:
_fellowSensorGroups
)
{
g
->
read
();
}
}
...
...
src/sensors/perfevent/PerfSensorGroup.h
View file @
73a85f92
...
...
@@ -11,6 +11,10 @@
#include
"../../includes/SensorGroupTemplate.h"
#include
"PerfSensorBase.h"
class
PerfSensorGroup
;
using
PerfSGPtr
=
std
::
shared_ptr
<
PerfSensorGroup
>
;
class
PerfSensorGroup
:
public
SensorGroupTemplate
<
PerfSensorBase
>
{
public:
PerfSensorGroup
(
const
std
::
string
&
name
);
...
...
@@ -26,7 +30,7 @@ public:
void
setSensorGroupLeader
(
bool
sensorGroupLeader
)
{
_sensorGroupLeader
=
sensorGroupLeader
;
}
void
setMaxCorrection
(
double
maxCorrection
){
_maxCorrection
=
maxCorrection
;
}
void
pushBackGroup
(
PerfS
ensorGroup
*
perfGroup
)
{
_fellowSensorGroups
.
push_back
(
perfGroup
);
}
void
pushBackGroup
(
PerfS
GPtr
perfGroup
)
{
_fellowSensorGroups
.
push_back
(
perfGroup
);
}
private:
void
read
()
override
;
...
...
@@ -44,7 +48,7 @@ private:
std
::
vector
<
uint64_t
>
_ids
;
//the sensorGroupLeader stores attached groups in here
std
::
vector
<
PerfS
ensorGroup
*
>
_fellowSensorGroups
;
std
::
vector
<
PerfS
GPtr
>
_fellowSensorGroups
;
uint64_t
_latest_time_enabled
;
uint64_t
_latest_time_running
;
...
...
src/sensors/perfevent/PerfeventConfigurator.cpp
View file @
73a85f92
...
...
@@ -169,7 +169,7 @@ bool PerfeventConfigurator::readConfig(std::string cfgPath) {
if
(
!
cpuSet
.
empty
())
{
//first create groupLeader
std
::
set
<
int
>::
iterator
it
=
cpuSet
.
begin
();
PerfS
ensorGroup
*
leaderSG
=
new
PerfSensorGroup
(
group
);
PerfS
GPtr
leaderSG
=
std
::
make_shared
<
PerfSensorGroup
>
(
group
);
leaderSG
->
setSensorGroupLeader
(
true
);
std
::
stringstream
mqttPart
;
mqttPart
<<
std
::
setfill
(
'0'
)
<<
std
::
setw
(
group
.
getMqttPart
().
size
())
<<
std
::
hex
<<
*
it
<<
"/"
;
...
...
@@ -182,7 +182,7 @@ bool PerfeventConfigurator::readConfig(std::string cfgPath) {
//create fellow groups
for
(;
it
!=
cpuSet
.
end
();
++
it
)
{
PerfS
ensorGroup
*
perfSG
=
new
PerfSensorGroup
(
group
);
PerfS
GPtr
perfSG
=
std
::
make_shared
<
PerfSensorGroup
>
(
group
);
std
::
stringstream
mqttPart
;
mqttPart
<<
std
::
setfill
(
'0'
)
<<
std
::
setw
(
group
.
getMqttPart
().
size
())
<<
std
::
hex
<<
*
it
<<
"/"
;
...
...
@@ -200,8 +200,8 @@ bool PerfeventConfigurator::readConfig(std::string cfgPath) {
}
}
//read of config finished. Now we build the mqtt-topic for every sensor
for
(
auto
g
:
_sensorGroups
)
{
for
(
auto
s
:
g
->
getSensors
())
{
for
(
const
auto
&
g
:
_sensorGroups
)
{
for
(
const
auto
&
s
:
g
->
getSensors
())
{
s
->
setMqtt
(
_mqttPrefix
+
g
->
getMqttPart
()
+
s
->
getMqtt
());
}
}
...
...
src/sensors/procfs/ProcfsConfigurator.cpp
View file @
73a85f92
...
...
@@ -98,7 +98,7 @@ bool ProcfsConfigurator::readConfig(std::string cfgPath) {
}
else
if
(
boost
::
iequals
(
val
.
first
,
_groupName
))
{
LOG
(
debug
)
<<
_groupName
<<
"
\"
"
<<
val
.
second
.
data
()
<<
"
\"
"
;
if
(
!
val
.
second
.
empty
())
{
ProcfsS
ensorGroup
*
group
=
new
ProcfsSensorGroup
(
val
.
second
.
data
());
ProcfsS
GPtr
group
=
std
::
make_shared
<
ProcfsSensorGroup
>
(
val
.
second
.
data
());
if
(
readSensorGroup
(
*
group
,
val
.
second
))
{
storeSensorGroup
(
group
);
}
else
{
...
...
@@ -141,7 +141,7 @@ void ProcfsConfigurator::sensorGroup(ProcfsSensorGroup& sGroup, CFG_VAL config)
std
::
string
filePath
=
""
,
fileType
=
""
,
mqttStart
=
"00"
;
// Set of cpu ids read during configuration
std
::
set
<
int
>
cpuSet
;
std
::
vector
<
ProcfsS
ensorBase
*
>
derivedSensors
;
std
::
vector
<
ProcfsS
BPtr
>
derivedSensors
;
ProcfsParser
*
parser
;
BOOST_FOREACH
(
boost
::
property_tree
::
iptree
::
value_type
&
val
,
config
)
{
...
...
@@ -200,7 +200,7 @@ void ProcfsConfigurator::sensorGroup(ProcfsSensorGroup& sGroup, CFG_VAL config)
// Adding the sensors corresponding to availableMetrics
for
(
int
i
=
0
;
i
<
numMetrics
;
i
++
)
{
ProcfsS
ensorBase
*
sensor
=
(
ProcfsSensorBase
*
)
sGroup
.
getSensors
().
at
(
i
);
const
ProcfsS
BPtr
&
sensor
=
sGroup
.
get
Derived
Sensors
().
at
(
i
);
if
(
autoMQTT
)
sensor
->
setMqtt
(
this
->
increaseMqtt
(
mqttStart
,
metricsCounter
->
at
(
sensor
->
getCPUId
()
+
1
)
++
));
// If the metric does not refer to a specific CPU core, the topic is prefix + default mqttPart + suffix
// The suffix is increased automatically through the metricsCounter vector
...
...
src/sensors/procfs/ProcfsParser.cpp
View file @
73a85f92
...
...
@@ -46,15 +46,15 @@ ProcfsParser::~ProcfsParser() { this->close(); }
* metrics for all available CPUs in the system will be extracted.
* @return true if initialization was successful, false otherwise
*/
bool
ProcfsParser
::
init
(
std
::
vector
<
ProcfsS
ensorBase
*
>
*
sensorVec
,
std
::
set
<
int
>
*
cpuSet
)
{
bool
ProcfsParser
::
init
(
std
::
vector
<
ProcfsS
BPtr
>
*
sensorVec
,
std
::
set
<
int
>
*
cpuSet
)
{
if
(
this
->
_initialized
)
return
true
;
if
((
this
->
_metricsFile
=
fopen
(
this
->
_path
.
c_str
(),
"r"
))
==
NULL
)
return
false
;
// Building the auxiliary sensor map
std
::
map
<
std
::
string
,
ProcfsS
ensorBase
*
>
*
sensorMap
=
sensorVec
!=
NULL
?
new
std
::
map
<
std
::
string
,
ProcfsS
ensorBase
*
>
()
:
NULL
;
std
::
map
<
std
::
string
,
ProcfsS
BPtr
>
*
sensorMap
=
sensorVec
!=
NULL
?
new
std
::
map
<
std
::
string
,
ProcfsS
BPtr
>
()
:
NULL
;
if
(
sensorVec
!=
NULL
)
for
(
auto
s
:
*
sensorVec
)
for
(
auto
&
s
:
*
sensorVec
)
sensorMap
->
insert
(
std
::
make_pair
(
s
->
getMetric
(),
s
));
// For the parser to be initialized, both the metrics' names and initial readings must be successfully read
...
...
@@ -84,7 +84,6 @@ void ProcfsParser::close() {
delete
this
->
_readings
;
}
if
(
this
->
_sensors
!=
NULL
)
{
for
(
auto
s
:
*
this
->
_sensors
)
delete
s
;
this
->
_sensors
->
clear
();
delete
this
->
_sensors
;
}
...
...
@@ -104,7 +103,7 @@ void ProcfsParser::close() {
*
* @return Pointer to a vector of ProcfsSensorBase objects if the parser is initialized and no errors are encountered, NULL otherwise
*/
std
::
vector
<
ProcfsS
ensorBase
*
>
*
ProcfsParser
::
getSensors
()
{
std
::
vector
<
ProcfsS
BPtr
>
*
ProcfsParser
::
getSensors
()
{
if
(
!
this
->
_initialized
)
return
NULL
;
return
this
->
_sensors
;
...
...
@@ -138,12 +137,12 @@ std::vector<reading_t> *ProcfsParser::readSensors() {
* metrics for all available CPUs in the system will be extracted.
* @return true if successful, false otherwise
*/
bool
MeminfoParser
::
_readNames
(
std
::
map
<
std
::
string
,
ProcfsS
ensorBase
*
>
*
sensorMap
,
std
::
set
<
int
>
*
cpuSet
)
{
bool
MeminfoParser
::
_readNames
(
std
::
map
<
std
::
string
,
ProcfsS
BPtr
>
*
sensorMap
,
std
::
set
<
int
>
*
cpuSet
)
{
if
(
this
->
_sensors
==
NULL
)
{
bool
memUsedEnabled
=
sensorMap
!=
NULL
&&
!
sensorMap
->
empty
()
&&
sensorMap
->
find
(
this
->
_memUsedToken
)
!=
sensorMap
->
end
();
this
->
_memFreeLine
=
-
1
;
this
->
_memTotalLine
=
-
1
;
this
->
_sensors
=
new
std
::
vector
<
ProcfsS
ensorBase
*
>
();
this
->
_sensors
=
new
std
::
vector
<
ProcfsS
BPtr
>
();
this
->
_skipLine
.
clear
();
char
*
lineToken
,
*
savePtr
;
fseek
(
this
->
_metricsFile
,
0
,
SEEK_SET
);
...
...
@@ -161,9 +160,9 @@ bool MeminfoParser::_readNames(std::map<std::string, ProcfsSensorBase*> *sensorM
// We check if the token matches one entry in sensorMap, meaning that it must be extracted
else
if
(
sensorMap
==
NULL
||
sensorMap
->
empty
()
||
sensorMap
->
find
(
lineToken
)
!=
sensorMap
->
end
()
)
{
if
(
sensorMap
==
NULL
||
sensorMap
->
empty
()
)
this
->
_sensors
->
push_back
(
new
ProcfsSensorBase
(
std
::
string
(
lineToken
),
std
::
string
(
lineToken
)));
this
->
_sensors
->
push_back
(
std
::
make_shared
<
ProcfsSensorBase
>
(
std
::
string
(
lineToken
),
std
::
string
(
lineToken
)));
else
this
->
_sensors
->
push_back
(
new
ProcfsSensorBase
(
*
sensorMap
->
find
(
lineToken
)
->
second
));
this
->
_sensors
->
push_back
(
std
::
make_shared
<
ProcfsSensorBase
>
(
*
sensorMap
->
find
(
lineToken
)
->
second
));
this
->
_skipLine
.
push_back
(
false
);
}
// If the token does not match any entry in sensorMap, its line is flagged as ignored
...
...
@@ -179,7 +178,7 @@ bool MeminfoParser::_readNames(std::map<std::string, ProcfsSensorBase*> *sensorM
// If MemUsed was requested and both MemTotal and MemFree were found, we create a new sensor
if
(
this
->
_memTotalLine
!=
-
1
&&
this
->
_memFreeLine
!=
-
1
)
this
->
_sensors
->
push_back
(
new
ProcfsSensorBase
(
*
sensorMap
->
find
(
this
->
_memUsedToken
)
->
second
));
this
->
_sensors
->
push_back
(
std
::
make_shared
<
ProcfsSensorBase
>
(
*
sensorMap
->
find
(
this
->
_memUsedToken
)
->
second
));
this
->
_numMetrics
=
this
->
_sensors
->
size
();
}
...
...
@@ -262,14 +261,14 @@ bool MeminfoParser::_readMetrics() {
* metrics for all available CPUs in the system will be extracted.
* @return true if successful, false otherwise
*/
bool
ProcstatParser
::
_readNames
(
std
::
map
<
std
::
string
,
ProcfsS
ensorBase
*
>
*
sensorMap
,
std
::
set
<
int
>
*
cpuSet
)
{
bool
ProcstatParser
::
_readNames
(
std
::
map
<
std
::
string
,
ProcfsS
BPtr
>
*
sensorMap
,
std
::
set
<
int
>
*
cpuSet
)
{
if
(
this
->
_sensors
==
NULL
)
{
this
->
_sensors
=
new
std
::
vector
<
ProcfsS
ensorBase
*
>
();
this
->
_sensors
=
new
std
::
vector
<
ProcfsS
BPtr
>
();
this
->
_skipLine
.
clear
();
this
->
_skipColumn
.
clear
();
char
*
lineToken
,
*
savePtr
;
short
currCPU
=
-
1
,
colCtr
=
0
,
parsedCols
=
0
;
ProcfsS
ensorBase
*
s
=
NULL
;
ProcfsS
BPtr
s
=
NULL
;
// We detect which columns in the procstat file, corresponding to CPU-specific metrics must be skipped or
// considered depending on the sensors in the sensormap
...
...
@@ -318,11 +317,11 @@ bool ProcstatParser::_readNames(std::map<std::string, ProcfsSensorBase*> *sensor
while
((
lineToken
=
strtok_r
(
this
->
_stringBuffer
,
this
->
LINE_SEP
,
&
savePtr
))
!=
NULL
&&
colCtr
<
this
->
DEFAULTMETRICS
)
{
if
(
this
->
_skipColumn
[
colCtr
]
==
1
||
(
this
->
_skipColumn
[
colCtr
]
==
2
&&
currCPU
==
-
1
)
)
{
if
(
sensorMap
!=
NULL
&&
!
sensorMap
->
empty
()
)
{
s
=
new
ProcfsSensorBase
(
*
sensorMap
->
find
(
this
->
DEFAULT_NAMES
[
colCtr
])
->
second
);
s
=
std
::
make_shared
<
ProcfsSensorBase
>
(
*
sensorMap
->
find
(
this
->
DEFAULT_NAMES
[
colCtr
])
->
second
);
s
->
setName
(
currCPU
==
-
1
?
s
->
getName
()
:
cpuName
+
"_"
+
s
->
getName
());
}
else
s
=
new
ProcfsSensorBase
(
currCPU
==
-
1
?
this
->
DEFAULT_NAMES
[
colCtr
]
:
cpuName
+
"_"
+
this
->
DEFAULT_NAMES
[
colCtr
]);
s
=
std
::
make_shared
<
ProcfsSensorBase
>
(
currCPU
==
-
1
?
this
->
DEFAULT_NAMES
[
colCtr
]
:
cpuName
+
"_"
+
this
->
DEFAULT_NAMES
[
colCtr
]);
s
->
setMetric
(
currCPU
==
-
1
?
this
->
DEFAULT_NAMES
[
colCtr
]
:
cpuName
+
"_"
+
this
->
DEFAULT_NAMES
[
colCtr
]
);
s
->
setCPUId
(
currCPU
);
...
...
@@ -345,9 +344,9 @@ bool ProcstatParser::_readNames(std::map<std::string, ProcfsSensorBase*> *sensor
this
->
_skipLine
.
push_back
(
true
);
else
{
if
(
sensorMap
!=
NULL
&&
!
sensorMap
->
empty
())
s
=
new
ProcfsSensorBase
(
*
sensorMap
->
find
(
lineToken
)
->
second
);
s
=
std
::
make_shared
<
ProcfsSensorBase
>
(
*
sensorMap
->
find
(
lineToken
)
->
second
);
else
s
=
new
ProcfsSensorBase
(
std
::
string
(
lineToken
));
s
=
std
::
make_shared
<
ProcfsSensorBase
>
(
std
::
string
(
lineToken
));
s
->
setCPUId
(
-
1
);
s
->
setMetric
(
std
::
string
(
lineToken
));
this
->
_sensors
->
push_back
(
s
);
...
...
src/sensors/procfs/ProcfsParser.h
View file @
73a85f92
...
...
@@ -30,7 +30,7 @@ public:
virtual
~
ProcfsParser
();
// Init/close methods
bool
init
(
std
::
vector
<
ProcfsS
ensorBase
*
>
*
sensorVec
=
NULL
,
std
::
set
<
int
>
*
cpuSet
=
NULL
);
bool
init
(
std
::
vector
<
ProcfsS
BPtr
>
*
sensorVec
=
NULL
,
std
::
set
<
int
>
*
cpuSet
=
NULL
);
virtual
void
close
();
// Setters and getters
...
...
@@ -39,18 +39,18 @@ public:
unsigned
int
getNumMetrics
()
{
return
this
->
_numMetrics
;
}
unsigned
int
getNumCPUs
()
{
return
this
->
_numCPUs
;
}
std
::
vector
<
ProcfsS
ensorBase
*
>
*
getSensors
();
std
::
vector
<
ProcfsS
BPtr
>
*
getSensors
();
std
::
vector
<
reading_t
>
*
readSensors
();
protected:
// Private parsing methods that implement all necessary logic to parse metrics' names (and associated CPU cores, if any)
// and values. MUST be overridden by children classes
virtual
bool
_readNames
(
std
::
map
<
std
::
string
,
ProcfsS
ensorBase
*
>
*
sensorMap
,
std
::
set
<
int
>
*
cpuSet
)
{
return
false
;
};
virtual
bool
_readNames
(
std
::
map
<
std
::
string
,
ProcfsS
BPtr
>
*
sensorMap
,
std
::
set
<
int
>
*
cpuSet
)
{
return
false
;
};
virtual
bool
_readMetrics
()
{
return
false
;
};
// Vector containing the names of parsed metrics, associated CPU cores (if any), and values.
// After initialization, _sensors is always non-NULL.
std
::
vector
<
ProcfsS
ensorBase
*
>
*
_sensors
;
std
::
vector
<
ProcfsS
BPtr
>
*
_sensors
;
std
::
vector
<
reading_t
>
*
_readings
;
// Keeps track of which lines and columns in the parsed file must be skipped
...
...
@@ -81,7 +81,7 @@ public:
MeminfoParser
(
const
std
::
string
path
=
""
)
:
ProcfsParser
(
path
)
{
this
->
LINE_SEP
=
" :
\t
"
;
if
(
path
==
""
)
this
->
_path
=
"/proc/meminfo"
;
else
this
->
_path
=
path
;
}
protected:
bool
_readNames
(
std
::
map
<
std
::
string
,
ProcfsS
ensorBase
*
>
*
sensorMap
,
std
::
set
<
int
>
*
cpuSet
)
override
;
bool
_readNames
(
std
::
map
<
std
::
string
,
ProcfsS
BPtr
>
*
sensorMap
,
std
::
set
<
int
>
*
cpuSet
)
override
;
bool
_readMetrics
()
override
;
unsigned
int
_memTotalLine
;
...
...
@@ -119,7 +119,7 @@ public:
ProcstatParser
(
const
std
::
string
path
=
""
)
:
ProcfsParser
(
path
)
{
this
->
LINE_SEP
=
"
\t
"
;
if
(
path
==
""
)
this
->
_path
=
"/proc/stat"
;
else
this
->
_path
=
path
;
}
protected:
bool
_readNames
(
std
::
map
<
std
::
string
,
ProcfsS
ensorBase
*
>
*
sensorMap
,
std
::
set
<
int
>
*
cpuSet
)
override
;
bool
_readNames
(
std
::
map
<
std
::
string
,
ProcfsS
BPtr
>
*
sensorMap
,
std
::
set
<
int
>
*
cpuSet
)
override
;
bool
_readMetrics
()
override
;
// Internal variables
...
...
src/sensors/procfs/ProcfsSensorBase.h
View file @
73a85f92
...
...
@@ -57,4 +57,6 @@ protected:
};
using
ProcfsSBPtr
=
std
::
shared_ptr
<
ProcfsSensorBase
>
;
#endif
/* PROCFSSENSOR_H_ */
src/sensors/procfs/ProcfsSensorGroup.cpp
View file @
73a85f92
...
...
@@ -27,20 +27,18 @@ ProcfsSensorGroup::~ProcfsSensorGroup() {
* @param newSensors: Vector of ProcfsSensorBase objects to replace the old set
*
*/
void
ProcfsSensorGroup
::
replaceSensors
(
std
::
vector
<
ProcfsS
ensorBase
*
>
*
newSensors
)
{
void
ProcfsSensorGroup
::
replaceSensors
(
std
::
vector
<
ProcfsS
BPtr
>
*
newSensors
)
{
std
::
set
<
std
::
string
>
sensorSet
=
std
::
set
<
std
::
string
>
();
for
(
auto
s_new
:
*
newSensors
)
sensorSet
.
insert
(
s_new
->
getMetric
()
);
for
(
auto
s
:
this
->
_sensors
)
{
for
(
const
auto
&
s_new
:
*
newSensors
)
sensorSet
.
insert
(
s_new
->
getMetric
()
);
for
(
const
auto
&
s
:
this
->
_sensors
)
{
if
(
sensorSet
.
find
(
s
->
getMetric
())
==
sensorSet
.
end
()
)
LOG
(
warning
)
<<
_groupName
<<
"::Sensor "
<<
s
->
getName
()
<<
" could not be matched to any metric!"
;
// We clean up the original sensor
delete
s
;
}
sensorSet
.
clear
();
this
->
_sensors
.
clear
();
this
->
_baseSensors
.
clear
();
for
(
auto
s
:
*
newSensors
)
this
->
pushBackSensor
(
new
ProcfsSensorBase
(
*
s
));
for
(
auto
s
:
*
newSensors
)
this
->
pushBackSensor
(
std
::
make_shared
<
ProcfsSensorBase
>
(
*
s
));
}
/**
...
...
src/sensors/procfs/ProcfsSensorGroup.h
View file @
73a85f92
...
...
@@ -35,8 +35,8 @@ public:
std
::
string
getType
()
{
return
this
->
_type
;
}
// Method to get the internal sensor vector used by the sensor group (different from getSensors)
std
::
vector
<
ProcfsS
ensorBase
*
>
getDerivedSensors
()
{
return
this
->
_sensors
;
}
void
replaceSensors
(
std
::
vector
<
ProcfsS
ensorBase
*
>
*
newSensors
);
std
::
vector
<
ProcfsS
BPtr
>
getDerivedSensors
()
{
return
this
->
_sensors
;
}
//TODO return reference?
void
replaceSensors
(
std
::
vector
<
ProcfsS
BPtr
>
*
newSensors
);
private:
// Methods inherited from SensorGroupTemplate
...
...
@@ -53,4 +53,6 @@ private:
};
using
ProcfsSGPtr
=
std
::
shared_ptr
<
ProcfsSensorGroup
>
;
#endif
/* PROCFSSENSORGROUP_H_ */
src/sensors/snmp/SNMPSensorGroup.cpp
View file @
73a85f92
...
...
@@ -50,7 +50,7 @@ void SNMPSensorGroup::read() {
reading_t
reading
;
reading
.
timestamp
=
getTimestamp
();
for
(
auto
s
:
_sensors
)
{
for
(
const
auto
&
s
:
_sensors
)
{
try
{
reading
.
value
=
_connection
->
issueGet
(
s
->
getOID
(),
s
->
getOIDLen
());
#ifdef DEBUG
...
...
src/sensors/sysfs/SysfsSensorGroup.cpp
View file @
73a85f92
...
...
@@ -61,7 +61,7 @@ void SysfsSensorGroup::read() {
if
(
nelem
)
{
buf
[
nelem
-
1
]
=
0
;
for
(
auto
s
:
_sensors
)
{
for
(
const
auto
&
s
:
_sensors
)
{
reading
.
value
=
0
;
try
{
//filter the payload if necessary
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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