forked from opencurve/curve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
topology_metric.h
471 lines (434 loc) · 16.9 KB
/
topology_metric.h
1
2
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
/*
* Copyright (c) 2020 NetEase Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Project: curve
* Created Date: Thu Jun 27 2019
* Author: xuchaojie
*/
#ifndef SRC_MDS_TOPOLOGY_TOPOLOGY_METRIC_H_
#define SRC_MDS_TOPOLOGY_TOPOLOGY_METRIC_H_
#include <bvar/bvar.h>
#include <vector>
#include <map>
#include <string>
#include <memory>
#include <utility>
#include "src/mds/topology/topology_stat.h"
#include "src/mds/nameserver2/allocstatistic/alloc_statistic.h"
#include "src/common/interruptible_sleeper.h"
using ::curve::common::InterruptibleSleeper;
namespace curve {
namespace mds {
namespace topology {
struct ChunkServerMetric {
const std::string kTopologyChunkServerMetricPrefix =
"topology_metric_chunkserver_Id_";
// scatterWidth
bvar::Status<uint32_t> scatterWidth;
// copyset numbers
bvar::Status<uint32_t> copysetNum;
// leader numbers
bvar::Status<uint32_t> leaderNum;
// disk capacity
bvar::Status<uint64_t> diskCapacity;
// disk utilization
bvar::Status<uint64_t> diskUsed;
// number of leaders reported by heartbeat
bvar::Status<uint32_t> leaderCount;
// number of copyset reported by heartbeat
bvar::Status<uint32_t> copysetCount;
// bandwidth of reading
bvar::Status<uint32_t> readRate;
// bandwidth of writing
bvar::Status<uint32_t> writeRate;
// IOPS of reading
bvar::Status<uint32_t> readIOPS;
// IOPS of writing
bvar::Status<uint32_t> writeIOPS;
// disk capacity of chunkfilepool occupied by used chunks
bvar::Status<uint64_t> chunkSizeUsedBytes;
// disk capacity of chunkfilepool occupied by unused chunks
bvar::Status<uint64_t> chunkSizeLeftBytes;
// disk capacity of recycle bin occupied by chunks
bvar::Status<uint64_t> chunkSizeTrashedBytes;
// total capacity
bvar::Status<uint64_t> chunkSizeTotalBytes;
explicit ChunkServerMetric(ChunkServerIdType csId) :
scatterWidth(kTopologyChunkServerMetricPrefix,
std::to_string(csId) + "_scatterwidth", 0),
copysetNum(kTopologyChunkServerMetricPrefix,
std::to_string(csId) + "_copysetnum", 0),
leaderNum(kTopologyChunkServerMetricPrefix,
std::to_string(csId) + "_leadernum", 0),
diskCapacity(kTopologyChunkServerMetricPrefix,
std::to_string(csId) + "_diskCapacity", 0),
diskUsed(kTopologyChunkServerMetricPrefix,
std::to_string(csId) + "_diskUsed", 0),
leaderCount(kTopologyChunkServerMetricPrefix,
std::to_string(csId) + "_leaderCount_from_heartbeat", 0),
copysetCount(kTopologyChunkServerMetricPrefix,
std::to_string(csId) + "_copysetCount_from_heartbeat", 0),
readRate(kTopologyChunkServerMetricPrefix,
std::to_string(csId) + "_readRate", 0),
writeRate(kTopologyChunkServerMetricPrefix,
std::to_string(csId) + "_writeRate", 0),
readIOPS(kTopologyChunkServerMetricPrefix,
std::to_string(csId) + "_readIOPS", 0),
writeIOPS(kTopologyChunkServerMetricPrefix,
std::to_string(csId) + "_writeIOPS", 0),
chunkSizeUsedBytes(kTopologyChunkServerMetricPrefix,
std::to_string(csId) + "_chunkSizeUsedBytes", 0),
chunkSizeLeftBytes(kTopologyChunkServerMetricPrefix,
std::to_string(csId) + "_chunkSizeLeftBytes", 0),
chunkSizeTrashedBytes(kTopologyChunkServerMetricPrefix,
std::to_string(csId) + "_chunkSizeTrashedBytes", 0),
chunkSizeTotalBytes(kTopologyChunkServerMetricPrefix,
std::to_string(csId) + "_chunkSizeTotalBytes", 0) {}
};
using ChunkServerMetricPtr = std::unique_ptr<ChunkServerMetric>;
struct LogicalPoolMetric {
const std::string kTopologyLogicalPoolMetricPrefix =
"topology_metric_logicalPool_";
// server number
bvar::Status<uint32_t> serverNum;
// chunkserver number
bvar::Status<uint32_t> chunkServerNum;
// copyset number
bvar::Status<uint32_t> copysetNum;
// average scatterWidth
bvar::Status<double> scatterWidthAvg;
// variance of scatterWidth
bvar::Status<double> scatterWidthVariance;
// standard deviation of scatterWidth
bvar::Status<double> scatterWidthStandardDeviation;
// range of scatterWidth
bvar::Status<double> scatterWidthRange;
// minimum scatterWidth
bvar::Status<double> scatterWidthMin;
// maximum scatterWidth
bvar::Status<double> scatterWidthMax;
// average copyset number
bvar::Status<double> copysetNumAvg;
// variance of copyset number
bvar::Status<double> copysetNumVariance;
// standard deviation of copyset number
bvar::Status<double> copysetNumStandardDeviation;
// range of copyset number
bvar::Status<double> copysetNumRange;
// minimum copyset number
bvar::Status<double> copysetNumMin;
// maximum copyset number
bvar::Status<double> copysetNumMax;
// average value of leader number
bvar::Status<double> leaderNumAvg;
// variance of leader number
bvar::Status<double> leaderNumVariance;
// standard deviation of leader number
bvar::Status<double> leaderNumStandardDeviation;
// range of leader number
bvar::Status<double> leaderNumRange;
// minimum leader number
bvar::Status<double> leaderNumMin;
// maximum leader number
bvar::Status<double> leaderNumMax;
// capacity of the whole logical pool, which is also
// the capacity of the whole physical pool
bvar::Status<uint64_t> diskCapacity;
// capacity allocated of the entire logical pool / physical pool
bvar::Status<uint64_t> diskAlloc;
// utilization of the entire logical pool / physical pool
bvar::Status<uint64_t> diskUsed;
// disk capacity occupied by used chunks
bvar::Status<uint64_t> chunkSizeUsedBytes;
// disk capacity occupied by unused chunks in chunkfilepool
bvar::Status<uint64_t> chunkSizeLeftBytes;
// capacity occupied by chunks in recycle bin
bvar::Status<uint64_t> chunkSizeTrashedBytes;
// total capacity
bvar::Status<uint64_t> chunkSizeTotalBytes;
// logical total capacity
bvar::Status<uint64_t> logicalCapacity;
// bytes have alloced
bvar::Status<uint64_t> logicalAlloc;
// bandwidth of reading
bvar::Status<uint64_t> readRate;
// bandwidth of writing
bvar::Status<uint64_t> writeRate;
// IOPS of reading
bvar::Status<uint64_t> readIOPS;
// IOPS of writing
bvar::Status<uint64_t> writeIOPS;
explicit LogicalPoolMetric(const std::string &logicalPoolName) :
serverNum(kTopologyLogicalPoolMetricPrefix,
logicalPoolName + "_server_num", 0),
chunkServerNum(kTopologyLogicalPoolMetricPrefix,
logicalPoolName + "_chunkserver_num", 0),
copysetNum(kTopologyLogicalPoolMetricPrefix,
logicalPoolName + "_copyset_num", 0),
scatterWidthAvg(kTopologyLogicalPoolMetricPrefix,
logicalPoolName + "_scatterwidth_avg", 0),
scatterWidthVariance(kTopologyLogicalPoolMetricPrefix,
logicalPoolName + "_scatterwidth_variance", 0),
scatterWidthStandardDeviation(kTopologyLogicalPoolMetricPrefix,
logicalPoolName + "_scatterwidth_standard_deviation", 0),
scatterWidthRange(kTopologyLogicalPoolMetricPrefix,
logicalPoolName + "_scatterwidth_range", 0),
scatterWidthMin(kTopologyLogicalPoolMetricPrefix,
logicalPoolName + "_scatterwidth_min", 0),
scatterWidthMax(kTopologyLogicalPoolMetricPrefix,
logicalPoolName + "_scatterwidth_max", 0),
copysetNumAvg(kTopologyLogicalPoolMetricPrefix,
logicalPoolName + "_copysetnum_avg", 0),
copysetNumVariance(kTopologyLogicalPoolMetricPrefix,
logicalPoolName + "_copysetnum_variance", 0),
copysetNumStandardDeviation(kTopologyLogicalPoolMetricPrefix,
logicalPoolName + "_copysetnum_standard_deviation", 0),
copysetNumRange(kTopologyLogicalPoolMetricPrefix,
logicalPoolName + "_copysetnum_range", 0),
copysetNumMin(kTopologyLogicalPoolMetricPrefix,
logicalPoolName + "_copysetnum_min", 0),
copysetNumMax(kTopologyLogicalPoolMetricPrefix,
logicalPoolName + "_copysetnum_max", 0),
leaderNumAvg(kTopologyLogicalPoolMetricPrefix,
logicalPoolName + "_leadernum_avg", 0),
leaderNumVariance(kTopologyLogicalPoolMetricPrefix,
logicalPoolName + "_leadernum_variance", 0),
leaderNumStandardDeviation(kTopologyLogicalPoolMetricPrefix,
logicalPoolName + "_leadernum_standard_deviation", 0),
leaderNumRange(kTopologyLogicalPoolMetricPrefix,
logicalPoolName + "_leadernum_range", 0),
leaderNumMin(kTopologyLogicalPoolMetricPrefix,
logicalPoolName + "_leadernum_min", 0),
leaderNumMax(kTopologyLogicalPoolMetricPrefix,
logicalPoolName + "_leadernum_max", 0),
diskCapacity(kTopologyLogicalPoolMetricPrefix,
logicalPoolName + "_diskCapacity", 0),
diskAlloc(kTopologyLogicalPoolMetricPrefix,
logicalPoolName + "_diskAlloc", 0),
diskUsed(kTopologyLogicalPoolMetricPrefix,
logicalPoolName + "_diskUsed", 0),
chunkSizeUsedBytes(kTopologyLogicalPoolMetricPrefix,
logicalPoolName + "_chunkSizeUsedBytes", 0),
chunkSizeLeftBytes(kTopologyLogicalPoolMetricPrefix,
logicalPoolName + "_chunkSizeLeftBytes", 0),
chunkSizeTrashedBytes(kTopologyLogicalPoolMetricPrefix,
logicalPoolName + "_chunkSizeTrashedBytes", 0),
chunkSizeTotalBytes(kTopologyLogicalPoolMetricPrefix,
logicalPoolName + "_chunkSizeTotalBytes", 0),
logicalCapacity(kTopologyLogicalPoolMetricPrefix,
logicalPoolName + "_logicalCapacity", 0),
logicalAlloc(kTopologyLogicalPoolMetricPrefix,
logicalPoolName + "_logicalAlloc", 0),
readRate(kTopologyLogicalPoolMetricPrefix,
logicalPoolName + "_readRate", 0),
writeRate(kTopologyLogicalPoolMetricPrefix,
logicalPoolName + "_writeRate", 0),
readIOPS(kTopologyLogicalPoolMetricPrefix,
logicalPoolName + "_readIOPS", 0),
writeIOPS(kTopologyLogicalPoolMetricPrefix,
logicalPoolName + "_writeIOPS", 0)
{}
};
using LogicalPoolMetricPtr = std::unique_ptr<LogicalPoolMetric>;
struct ClusterMetric {
const std::string kTopologyClusterMetricPrefix =
"topology_metric_cluster_";
// server number
bvar::Status<uint32_t> serverNum;
// chunkserver number
bvar::Status<uint32_t> chunkServerNum;
// copyset number
bvar::Status<uint32_t> copysetNum;
// logical pool number
bvar::Status<uint32_t> logicalPoolNum;
// bandwidth of reading
bvar::Status<uint64_t> readRate;
// bandwidth of writing
bvar::Status<uint64_t> writeRate;
// IOPS of reading
bvar::Status<uint64_t> readIOPS;
// IOPS of writing
bvar::Status<uint64_t> writeIOPS;
// logical total capacity
bvar::Status<uint64_t> logicalCapacity;
// bytes have alloced
bvar::Status<uint64_t> logicalAlloc;
ClusterMetric() :
serverNum(kTopologyClusterMetricPrefix,
+ "server_num", 0),
chunkServerNum(kTopologyClusterMetricPrefix,
+ "chunkserver_num", 0),
copysetNum(kTopologyClusterMetricPrefix,
+ "copyset_num", 0),
logicalPoolNum(kTopologyClusterMetricPrefix,
+ "logicalpool_num", 0),
readRate(kTopologyClusterMetricPrefix,
+ "readRate", 0),
writeRate(kTopologyClusterMetricPrefix,
+ "writeRate", 0),
readIOPS(kTopologyClusterMetricPrefix,
+ "readIOPS", 0),
writeIOPS(kTopologyClusterMetricPrefix,
+ "writeIOPS", 0),
logicalCapacity(kTopologyClusterMetricPrefix,
+ "logicalCapacity", 0),
logicalAlloc(kTopologyClusterMetricPrefix,
+ "logicalAlloc", 0) {}
};
using ClusterMetricPtr = std::unique_ptr<ClusterMetric>;
extern std::map<PoolIdType, LogicalPoolMetricPtr> gLogicalPoolMetrics;
extern std::map<ChunkServerIdType, ChunkServerMetricPtr> gChunkServerMetrics;
extern ClusterMetricPtr gClusterMetrics;
class TopologyMetricService {
public:
struct ChunkServerMetricInfo {
// scatterWidth
uint32_t scatterWidth;
// copyset number
uint32_t copysetNum;
// leader number
uint32_t leaderNum;
ChunkServerMetricInfo() :
scatterWidth(0),
copysetNum(0),
leaderNum(0) {}
};
struct LogicalPoolMetricInfo {
// average scatterWidth
double scatterWidthAvg;
// variance of scatterWidth
double scatterWidthVariance;
// standard deviation of scatterWidth
double scatterWidthStandardDeviation;
// range of scatterWidth
double scatterWidthRange;
// minimum scatterWidth
double scatterWidthMin;
// maximum scatterWidth
double scatterWidthMax;
// average value of copyset number
double copysetNumAvg;
// variance of copyset number
double copysetNumVariance;
// standard deviation of copyset
double copysetNumStandardDeviation;
// range if copyset number
double copysetNumRange;
// minumum copyset number
double copysetNumMin;
// maximum copyset number
double copysetNumMax;
// average leader number
double leaderNumAvg;
// variance of leader number
double leaderNumVariance;
// standard deviation of leader number
double leaderNumStandardDeviation;
// range of leader number
double leaderNumRange;
// minimum leader number
double leaderNumMin;
// maximum leader number
double leaderNumMax;
LogicalPoolMetricInfo() :
scatterWidthAvg(0.0),
scatterWidthVariance(0.0),
scatterWidthStandardDeviation(0.0),
scatterWidthRange(0.0),
scatterWidthMin(0.0),
scatterWidthMax(0.0),
copysetNumAvg(0.0),
copysetNumVariance(0.0),
copysetNumStandardDeviation(0.0),
copysetNumRange(0.0),
copysetNumMin(0.0),
copysetNumMax(0.0),
leaderNumAvg(0.0),
leaderNumVariance(0.0),
leaderNumStandardDeviation(0.0),
leaderNumRange(0.0),
leaderNumMin(0.0),
leaderNumMax(0.0) {}
};
public:
TopologyMetricService(std::shared_ptr<Topology> topo,
std::shared_ptr<TopologyStat> topoStat,
std::shared_ptr<AllocStatistic> allocStatistic)
: topo_(topo),
topoStat_(topoStat),
allocStatistic_(allocStatistic),
isStop_(true) {}
~TopologyMetricService() {
Stop();
}
int Init(const TopologyOption &option);
int Run();
int Stop();
void UpdateTopologyMetrics();
/**
* @brief calculate metric data of chunkserver
*
* @param copysets CopySetInfo list
* @param[out] csMetricInfoMap metric data
*/
void CalcChunkServerMetrics(const std::vector<CopySetInfo> ©sets,
std::map<ChunkServerIdType, ChunkServerMetricInfo> *csMetricInfoMap);
/**
* @brief calculate metric data of logical pool
*
* @param csMetricInfoMap metric data of chunkserver
* @param[out] poolMetricInfo metric data of logical pool
*/
void CalcLogicalPoolMetrics(
const std::map<ChunkServerIdType,
ChunkServerMetricInfo> &csMetricInfoMap,
LogicalPoolMetricInfo *poolMetricInfo);
private:
/**
* @brief backend function that executes UpdateTopologyMetrics regularly
*/
void BackEndFunc();
private:
/**
* @brief topology module
*/
std::shared_ptr<Topology> topo_;
/**
* @brief topology statistic module
*/
std::shared_ptr<TopologyStat> topoStat_;
/**
* @brief allocation statistic module
*/
std::shared_ptr<AllocStatistic> allocStatistic_;
/**
* @brief backend thread
*/
curve::common::Thread backEndThread_;
/**
* @brief flag marking out stopping the backend thread or not
*/
curve::common::Atomic<bool> isStop_;
InterruptibleSleeper sleeper_;
/**
* @brief topology options
*/
TopologyOption option_;
};
} // namespace topology
} // namespace mds
} // namespace curve
#endif // SRC_MDS_TOPOLOGY_TOPOLOGY_METRIC_H_