ProcfsSensorBase.h 3.2 KB
Newer Older
1
2
3
//================================================================================
// Name        : ProcfsSensorBase.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 : Sensor base class for Procfs plugin.
//================================================================================

//================================================================================
// 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
/**
 * @defgroup procfs ProcFS plugin
 * @ingroup  pusherplugins
Alessio Netti's avatar
Alessio Netti committed
31
 *
32
 * @brief Collect data from the /proc filesystem.
Alessio Netti's avatar
Alessio Netti committed
33
34
35
36
37
 */

#ifndef PROCFSSENSOR_H_
#define PROCFSSENSOR_H_

38
#include "sensorbase.h"
Alessio Netti's avatar
Alessio Netti committed
39
40

/**
41
42
43
 * @brief SensorBase specialization for this plugin.
 *
 * @details Adds two private members, cpuID and metric, to the SensorBase class.
Alessio Netti's avatar
Alessio Netti committed
44
 *
45
 * @ingroup procfs
Alessio Netti's avatar
Alessio Netti committed
46
 */
Alessio Netti's avatar
Alessio Netti committed
47
48
class ProcfsSensorBase : public SensorBase {

49
50
51
52
53
54
55
      public:
	// Constructor and destructor
	ProcfsSensorBase(const std::string &name)
	    : SensorBase(name) {
		_metric = "";
		_perCPU = false;
		_cpuId = -1;
56
		_deltaMax = ULLONG_MAX;
57
	}
Alessio Netti's avatar
Alessio Netti committed
58

59
60
61
62
63
64
	ProcfsSensorBase(const std::string &name, const std::string &metric, bool percpu = false, int cpuid = -1)
	    : SensorBase(name) {
		_metric = metric;
		_perCPU = percpu;
		_cpuId = cpuid;
	}
Alessio Netti's avatar
Alessio Netti committed
65

66
67
68
69
70
71
72
	// Copy constructor
	ProcfsSensorBase(ProcfsSensorBase &other)
	    : SensorBase(other) {
		_metric = other.getMetric();
		_perCPU = other.isPerCPU();
		_cpuId = other.getCPUId();
	}
Alessio Netti's avatar
Alessio Netti committed
73

74
	virtual ~ProcfsSensorBase() {}
Alessio Netti's avatar
Alessio Netti committed
75

76
77
78
79
80
81
	void        setMetric(std::string m) { _metric = m; }
	void        setPerCPU(bool p) { _perCPU = p; }
	void        setCPUId(int i) { _cpuId = i; }
	std::string getMetric() { return _metric; }
	int         getCPUId() { return _cpuId; }
	bool        isPerCPU() { return _perCPU; }
Alessio Netti's avatar
Alessio Netti committed
82

83
84
	void printConfig(LOG_LEVEL ll, LOGGER &lg, unsigned leadingSpaces = 16) {
		std::string leading(leadingSpaces, ' ');
Alessio Netti's avatar
Alessio Netti committed
85
86
87
		LOG_VAR(ll) << leading << "    Metric:            " << _metric;
		LOG_VAR(ll) << leading << "    CPU Id:            " << _cpuId;
		LOG_VAR(ll) << leading << "    PerCPU:            " << (_perCPU ? "enabled" : "disabled");
88
	}
89

90
91
92
93
94
      protected:
	// The metric field is used to decouple the sensor's name from its metric within the proc file
	std::string _metric;
	bool        _perCPU;
	int         _cpuId;
Alessio Netti's avatar
Alessio Netti committed
95
96
};

97
98
using ProcfsSBPtr = std::shared_ptr<ProcfsSensorBase>;

Alessio Netti's avatar
Alessio Netti committed
99
#endif /* PROCFSSENSOR_H_ */