The expiration time for new job artifacts in CI/CD pipelines is now 30 days (GitLab default). Previously generated artifacts in already completed jobs will not be affected by the change. The latest artifacts for all jobs in the latest successful pipelines will be kept. More information: https://gitlab.lrz.de/help/user/admin_area/settings/continuous_integration.html#default-artifacts-expiration

PerSystSqlOperator.h 5.36 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
	}

76
	void pushbackQuantileSensor(AggregatorSBPtr qSensor){
77
78
79
		_quantileSensors.push_back(qSensor);
	}

80
	void setSeverityExponent(double severityExponent) {
81
82
83
84
85
86
87
		_severity_exponent = severityExponent;
	}

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

88
	void setSeverityMaxMemory(double severityMaxMemory) {
89
90
91
		_severity_max_memory = severityMaxMemory;
	}

92
	void setSeverityThreshold(double severityThreshold) {
93
94
95
		_severity_threshold = severityThreshold;
	}

Carla Guillen's avatar
Carla Guillen committed
96
97
98
99
	void setGoBackInMs(int go_back_ms){
		_go_back_ns = go_back_ms * 1e6;
	}

100
101
102
103
	void setBackend(Backend_t backend) {
		_backend = backend;
	}

104
105
106
107
108
	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
109
		_conn.host = host;
110
111
112
	}

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

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

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

	void setMariaDBPort(int port){
Carla Guillen's avatar
Carla Guillen committed
125
		_conn.port = port;
126
127
128
	}

	void setMariaDBRotation(MariaDB::Rotation_t rotation){
Carla Guillen's avatar
Carla Guillen committed
129
130
131
132
133
134
135
		_conn.rotation = rotation;
	}

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

136
137
138
private:
	std::vector<reading_t> _buffer;
	std::vector<AggregatorSBPtr> _quantileSensors;
139
140
	unsigned int _number_of_even_quantiles;
	Formula _severity_formula;
141
142
143
	double _severity_threshold;
	double _severity_exponent;
	double _severity_max_memory;
Carla Guillen's avatar
Carla Guillen committed
144
145
	std::vector<double> _severities;
	int _go_back_ns;
146
	Backend_t _backend;
Carla Guillen's avatar
Carla Guillen committed
147
	double _scaling_factor;
Carla Guillen's avatar
Carla Guillen committed
148

Carla Guillen's avatar
Carla Guillen committed
149
150
151
152
153
154
	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
155
		MariaDB::Rotation_t rotation;
Carla Guillen's avatar
Carla Guillen committed
156
157
158
159
160
		unsigned int every_x_days;
	};

	MariaDB_conn_t _conn;
	int _property_id;
Carla Guillen Carias's avatar
Carla Guillen Carias committed
161
	MariaDB *_persystdb;
162
	const int SCALING_FACTOR_SEVERITY=1000000;
Carla Guillen's avatar
Carla Guillen committed
163

Carla Guillen's avatar
Carla Guillen committed
164
165
protected:
	virtual void compute(U_Ptr unit) override;
166
	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
167
	double computeSeverityAverage(vector<double> & buffer);
168
	void convertToDoubles(std::vector<reading_t> &buffer, std::vector<double> &douBuffer);
169
170
	bool execOnStart() override;
	void execOnStop() override;
171
172
};

173
174
175
176
177
178
179
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
180

181
#endif /* ANALYTICS_OPERATORS_PERSYSTSQL_PERSYSTSQLOPERATOR_H_ */