forked from opencurve/curve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scheduleMetrics.h
152 lines (133 loc) · 4.82 KB
/
scheduleMetrics.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
/*
* 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: 20190704
* Author: lixiaocui
*/
#ifndef SRC_MDS_SCHEDULE_SCHEDULEMETRICS_H_
#define SRC_MDS_SCHEDULE_SCHEDULEMETRICS_H_
#include <bvar/bvar.h>
#include <string>
#include <map>
#include <memory>
#include "src/mds/schedule/operatorController.h"
#include "src/common/stringstatus.h"
using ::curve::mds::heartbeat::ConfigChangeType;
using ::curve::common::StringStatus;
namespace curve {
namespace mds {
namespace schedule {
extern const char ADDPEER[];
extern const char REMOVEPEER[];
extern const char TRANSFERLEADER[];
extern const char CHANGEPEER[];
extern const char NORMAL[];
extern const char HIGH[];
class ScheduleMetrics {
public:
explicit ScheduleMetrics(std::shared_ptr<Topology> topo) :
operatorNum(ScheduleMetricsPrefix, "operator_num"),
addOpNum(ScheduleMetricsPrefix, "addPeer_num"),
removeOpNum(ScheduleMetricsPrefix, "removePeer_num"),
transferOpNum(ScheduleMetricsPrefix, "transferLeader_num"),
changeOpNum(ScheduleMetricsPrefix, "changePeer_num"),
normalOpNum(ScheduleMetricsPrefix, "normal_operator_num"),
highOpNum(ScheduleMetricsPrefix, "high_operator_num"),
topo_(topo) {}
/**
* @brief UpdateAddMetric Interface exposed to operatorContoller for
* updating metric when adding operator
*
* @param[in] op Specific operator
*/
void UpdateAddMetric(const Operator &op);
/**
* @brief UpdateMetric Interface exposed to operatorContoller for updating
* metric when deleting operator
*
* @param[in] op Specific operator
*/
void UpdateRemoveMetric(const Operator &op);
private:
/**
* @brief GetHostNameAndPortById Get hostName:port of chunkserver specified
* by its ID
*
* @param[in] csid Chunkserver ID
*
* @return hostName:port (a string)
*/
std::string GetHostNameAndPortById(ChunkServerIdType csid);
/**
* @brief GetOpPriorityStr Get the name of the priority level in string
*
* @param[in] pri Priority (OperatorPriority, which is an enum)
*
* @return corresponding level in string
*/
std::string GetOpPriorityStr(OperatorPriority pri);
/**
* @brief RemoveUpdateOperatorsMap Update operator map when removing one of
* them
*
* @param[in] op Specified operator
* @param[in] type Operator type, including AddPeer/RemovePeer/TransferLeader //NOLINT
* @param[in] target Target chunkserver to change
*/
void RemoveUpdateOperatorsMap(
const Operator &op, std::string type, ChunkServerIdType target);
/**
* @brief AddUpdateOperatorsMap Update operator map when adding a new one
*
* @param[in] op Specified operator
* @param[in] type Operator type, including AddPeer/RemovePeer/TransferLeader //NOLINT
* @param[in] target Target chunkserver to change
*/
void AddUpdateOperatorsMap(
const Operator &op, std::string type, ChunkServerIdType target);
/**
* @brief UpdateOperatorsMap Construct operator map for exporting and
* transfer to JSON format
*
* @param[in] op Specified operator
* @param[in] type Operator type, including AddPeer/RemovePeer/TransferLeader //NOLINT
* @param[in] target Target chunkserver
*/
void UpdateOperatorsMap(
const Operator &op, std::string type, ChunkServerIdType target);
public:
const std::string ScheduleMetricsPrefix = "mds_scheduler_metric_";
const std::string ScheduleMetricsCopySetOpPrefix =
"mds_scheduler_metric_copyset_";
// number of operator under execution
bvar::Adder<uint32_t> operatorNum;
// xxxNUM: number of operator xxx under execution
bvar::Adder<uint32_t> addOpNum;
bvar::Adder<uint32_t> removeOpNum;
bvar::Adder<uint32_t> transferOpNum;
bvar::Adder<uint32_t> changeOpNum;
bvar::Adder<uint32_t> normalOpNum;
bvar::Adder<uint32_t> highOpNum;
// specific operator under execution
std::map<CopySetKey, StringStatus> operators;
private:
std::shared_ptr<Topology> topo_;
};
} // namespace schedule
} // namespace mds
} // namespace curve
#endif // SRC_MDS_SCHEDULE_SCHEDULEMETRICS_H_