ProcfsSensorGroup.h 4.08 KB
Newer Older
1
2
3
//================================================================================
// Name        : ProcfsSensorGroup.h
// Author      : Alessio Netti
Micha Müller's avatar
Micha Müller committed
4
// Contact     : info@dcdb.it
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Copyright   : Leibniz Supercomputing Centre
// Description : Header file for Procfs sensor group class.
//================================================================================

//================================================================================
// This file is part of DCDB (DataCenter DataBase)
// Copyright (C) 2018-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.
//================================================================================
Alessio Netti's avatar
Alessio Netti committed
27
28
29
30
31
32
33
34

#ifndef PROCFSSENSORGROUP_H_
#define PROCFSSENSORGROUP_H_

#include "ProcfsParser.h"
#include "../../includes/SensorGroupTemplate.h"

/**
35
 * @brief SensorGroupTemplate specialization for this plugin.
Alessio Netti's avatar
Alessio Netti committed
36
 *
37
38
39
 * @details The ProcfsSensorGroup manages all sensors related to metrics in the
 *          same file. This is done in order to reduce parsing overhead, as all
 *          metrics are sampled in one reading pass.
Alessio Netti's avatar
Alessio Netti committed
40
 *
41
 * @ingroup procfs
Alessio Netti's avatar
Alessio Netti committed
42
43
 */
class ProcfsSensorGroup : public SensorGroupTemplate<ProcfsSensorBase> {
Alessio Netti's avatar
Alessio Netti committed
44

Alessio Netti's avatar
Alessio Netti committed
45
46
public:
    // Constructor and destructor
47
    ProcfsSensorGroup(const std::string& name) : SensorGroupTemplate(name) { _parser = NULL; _htVal=0; _scalingFactor=1000000; }
Alessio Netti's avatar
Alessio Netti committed
48
    ProcfsSensorGroup& operator=(const ProcfsSensorGroup& other);
Alessio Netti's avatar
Alessio Netti committed
49
    virtual ~ProcfsSensorGroup();
Alessio Netti's avatar
Alessio Netti committed
50
51
    
    // Methods inherited from SensorGroupTemplate
52
    bool execOnStart() final override;
Alessio Netti's avatar
Alessio Netti committed
53

Alessio Netti's avatar
Alessio Netti committed
54
    // Setters and getters
55
    void setHtVal(int htVal)              { this->_htVal = htVal; }
56
57
58
59
    void setParser(ProcfsParser *parser)  { this->_parser = parser; }
    void setType(std::string t)           { this->_type = t; }
    void setPath(std::string p)           { this->_path = p; }
    void setCpuSet(std::set<int> s)       { this->_cpuSet = s; }
60
    void setScalingFactor(uint64_t sf)    { if(sf>0) this->_scalingFactor = sf; }
61

62
    int getHtVal()                        { return this->_htVal; }
63
64
65
66
    ProcfsParser *getParser()             { return this->_parser; }
    std::string getType()                 { return this->_type; }
    std::string getPath()                 { return this->_path; }
    std::set<int> *getCpuSet()            { return &this->_cpuSet; }
67
    uint64_t getScalingFactor()           { return this->_scalingFactor; }
Alessio Netti's avatar
Alessio Netti committed
68

Alessio Netti's avatar
Alessio Netti committed
69
    // Method to get the internal sensor vector used by the sensor group (different from getSensors)
70
    std::vector<ProcfsSBPtr>& getDerivedSensors() { return this->_sensors; }
71
    void replaceSensors(std::vector<ProcfsSBPtr> *newSensors);
Alessio Netti's avatar
Alessio Netti committed
72

73
    void printGroupConfig(LOG_LEVEL ll, unsigned leadingSpaces=16) final override;
74

Alessio Netti's avatar
Alessio Netti committed
75
76
private:
    // Methods inherited from SensorGroupTemplate
77
    void read() final override;
Alessio Netti's avatar
Alessio Netti committed
78

Alessio Netti's avatar
Alessio Netti committed
79
80
81
82
    // ProcfsParser object to be used to extract metrics' values and names
    ProcfsParser *_parser;
    // Type of the ProcfsSensorGroup (i.e. vmstat, meminfo, procstat), currently unused
    std::string _type;
83
84
    // Path to the parsed file
    std::string _path;
85
86
    // Aggregation value for hyperthreading cores
    int _htVal;
87
88
    // Set of cpu ids read during configuration
    std::set<int> _cpuSet;
89
90
    // Scaling factor to be used for ratio metrics
    uint64_t _scalingFactor;
Alessio Netti's avatar
Alessio Netti committed
91

92
93
    std::vector<ureading_t> *_readingVector;
    ureading_t _readingBuffer;
Alessio Netti's avatar
Alessio Netti committed
94
95
};

96
97
using ProcfsSGPtr = std::shared_ptr<ProcfsSensorGroup>;

Alessio Netti's avatar
Alessio Netti committed
98
#endif /* PROCFSSENSORGROUP_H_ */