PerSystSqlOperator.h 5.48 KB
Newer Older
1
//================================================================================
2
// Name        : PerSystSqlOperator.h
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Author      : Carla Guillen
// Contact     : info@dcdb.it
// Copyright   : Leibniz Supercomputing Centre
// Description : Template implementing features to use Units in Operators.
//================================================================================

//================================================================================
// 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.
//================================================================================

28
29
#ifndef ANALYTICS_OPERATORS_PERSYSTSQL_PERSYSTSQLOPERATOR_H_
#define ANALYTICS_OPERATORS_PERSYSTSQL_PERSYSTSQLOPERATOR_H_
30

31
#include <string>
32
#include <vector>
33
#include <mutex>
34
35

#include "../../../common/include/cacheentry.h"
36
#include "../../../common/include/logging.h"
37
38
#include "../../includes/JobOperatorTemplate.h"
#include "../aggregator/AggregatorSensorBase.h"
Carla Guillen Carias's avatar
Carla Guillen Carias committed
39
#include "MariaDB.h"
40

41

42
class PerSystSqlOperator: public JobOperatorTemplate<AggregatorSensorBase>{
43
44
45
46
47
48
49
50
public:
	enum Formula {
		NOFORMULA = 0,
		FORMULA1 = 1,
		FORMULA2 = 2,
		FORMULA3 = 3,
		MEMORY_FORMULA = 4,
	};
51
52
53
54
55
56
57

	enum Backend_t {
		CASSANDRA = 0,
		MARIADB = 1,
		DEFAULT = MARIADB
	};

58
public:
59
60
	PerSystSqlOperator(const std::string& name);
	virtual ~PerSystSqlOperator();
61
62
63
64
	PerSystSqlOperator(const PerSystSqlOperator& other);
	PerSystSqlOperator& operator=(const PerSystSqlOperator& other);
	void copy(const PerSystSqlOperator& other);

65
	void compute(U_Ptr unit, qeJobData& jobData) override;
66
	void printConfig(LOG_LEVEL ll) override;
67
68

	unsigned int getNumberOfEvenQuantiles() const {
69
		return _number_of_even_quantiles;
70
71
72
	}

	void setNumberOfEvenQuantiles(unsigned int numberOfEvenQuantiles) {
73
		_number_of_even_quantiles = numberOfEvenQuantiles;
74
75
	}

Carla Guillen's avatar
Carla Guillen committed
76
77
78
79
	void setBatchDomain(int batch_domain){
		_batch_domain = batch_domain;
	}

80
	void pushbackQuantileSensor(AggregatorSBPtr qSensor){
81
82
83
		_quantileSensors.push_back(qSensor);
	}

84
	void setSeverityExponent(double severityExponent) {
85
86
87
88
89
90
91
		_severity_exponent = severityExponent;
	}

	void setSeverityFormula(Formula severityFormula) {
		_severity_formula = severityFormula;
	}

92
	void setSeverityMaxMemory(double severityMaxMemory) {
93
94
95
		_severity_max_memory = severityMaxMemory;
	}

96
	void setSeverityThreshold(double severityThreshold) {
97
98
99
		_severity_threshold = severityThreshold;
	}

Carla Guillen's avatar
Carla Guillen committed
100
101
102
103
	void setGoBackInMs(int go_back_ms){
		_go_back_ns = go_back_ms * 1e6;
	}

104
105
106
107
	void setBackend(Backend_t backend) {
		_backend = backend;
	}

108
109
110
111
112
	void setMariaDBEveryXDays(unsigned int every_x_days){
		_conn.every_x_days = every_x_days;
	}

	void setMariaDBHost(const std::string & host){
Carla Guillen's avatar
Carla Guillen committed
113
		_conn.host = host;
114
115
116
	}

	void setMariaDBUser(const std::string & user){
Carla Guillen's avatar
Carla Guillen committed
117
		_conn.user = user;
118
119
120
	}

	void setMariaDBPassword(const std::string & password){
Carla Guillen's avatar
Carla Guillen committed
121
		_conn.password = password;
122
123
124
	}

	void setMariaDBDatabaseName(const std::string & database_name){
Carla Guillen's avatar
Carla Guillen committed
125
		_conn.database_name = database_name;
126
127
128
	}

	void setMariaDBPort(int port){
Carla Guillen's avatar
Carla Guillen committed
129
		_conn.port = port;
130
131
132
	}

	void setMariaDBRotation(MariaDB::Rotation_t rotation){
Carla Guillen's avatar
Carla Guillen committed
133
134
135
136
137
138
139
		_conn.rotation = rotation;
	}

	void setPropertyId(int property_id){
		_property_id = property_id;
	}

140
141
142
private:
	std::vector<reading_t> _buffer;
	std::vector<AggregatorSBPtr> _quantileSensors;
143
	unsigned int _number_of_even_quantiles;
Carla Guillen's avatar
Carla Guillen committed
144
	int _batch_domain;
145
	Formula _severity_formula;
146
147
148
	double _severity_threshold;
	double _severity_exponent;
	double _severity_max_memory;
Carla Guillen's avatar
Carla Guillen committed
149
150
	std::vector<double> _severities;
	int _go_back_ns;
151
	Backend_t _backend;
Carla Guillen's avatar
Carla Guillen committed
152
	double _scaling_factor;
153
	bool _searchedOnceForMetaData;
Carla Guillen's avatar
Carla Guillen committed
154

Carla Guillen's avatar
Carla Guillen committed
155
156
157
158
159
160
	struct MariaDB_conn_t {
		std::string host;
		std::string user;
		std::string password;
		std::string database_name;
		int port;
Carla Guillen Carias's avatar
Carla Guillen Carias committed
161
		MariaDB::Rotation_t rotation;
Carla Guillen's avatar
Carla Guillen committed
162
163
164
165
166
		unsigned int every_x_days;
	};

	MariaDB_conn_t _conn;
	int _property_id;
Carla Guillen Carias's avatar
Carla Guillen Carias committed
167
	MariaDB *_persystdb;
168
	const int SCALING_FACTOR_SEVERITY=1000000;
Carla Guillen's avatar
Carla Guillen committed
169

Carla Guillen's avatar
Carla Guillen committed
170
171
protected:
	virtual void compute(U_Ptr unit) override;
172
	void compute_internal(U_Ptr& unit, vector<reading_t>& buffer, Aggregate_info_t &agg_info, uint64_t measurement_ts);
Carla Guillen's avatar
Carla Guillen committed
173
	double computeSeverityAverage(vector<double> & buffer);
174
	void convertToDoubles(std::vector<reading_t> &buffer, std::vector<double> &douBuffer);
175
176
	bool execOnStart() override;
	void execOnStop() override;
177
178
};

179
180
181
182
183
184
185
double severity_formula1(double metric, double threshold, double exponent);
double severity_formula2(double metric, double threshold, double exponent);
double severity_formula3(double metric, double threshold, double exponent);
double severity_memory(double metric, double threshold, double max_memory);
constexpr double severity_noformula(){return 0.0;} //No severity
void computeEvenQuantiles(std::vector<double> &data, const unsigned int NUMBER_QUANTILES, std::vector<double> &quantiles);

lu43jih's avatar
lu43jih committed
186

187
#endif /* ANALYTICS_OPERATORS_PERSYSTSQL_PERSYSTSQLOPERATOR_H_ */