forked from opencurve/curve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscheduleMetrics.h
155 lines (136 loc) · 4.87 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
152
153
154
/*
* 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 暴露给operatorContoller的接口,
* 用于增加operator的时候更新metric
*
* @param[in] op, 具体的operator
*/
void UpdateAddMetric(const Operator &op);
/**
* @brief UpdateMetric 暴露给operatorContoller的接口,
* 用于减少operator的时候更新metric
*
* @param[in] op, 具体的operator
*/
void UpdateRemoveMetric(const Operator &op);
private:
/**
* @brief GetHostNameAndPortById 获取指定chunkserverId的hostName:port
*
* @param[in] csid, 指定的chunkserver id
*
* @return hostName:port的表现形式
*/
std::string GetHostNameAndPortById(ChunkServerIdType csid);
/**
* @brief GetOpPriorityStr 获取operator优先级的string形式
*
* @param[in] pri, 指定优先级
*
* @return 优先级对应的string形式
*/
std::string GetOpPriorityStr(OperatorPriority pri);
/**
* @brief RemoveUpdateOperatorsMap remove operator时更新operator map
*
* @param[in] op, 具体operator
* @param[in] type, operator类型,包含AddPeer/RemovePeer/TransferLeader
* @param[in] target, 变更对象
*/
void RemoveUpdateOperatorsMap(
const Operator &op, std::string type, ChunkServerIdType target);
/**
* @brief AddUpdateOperatorsMap add operator时更新operator map
*
* @param[in] op, 具体operator
* @param[in] type, operator类型,包含AddPeer/RemovePeer/TransferLeader
* @param[in] target, 变更对象
*/
void AddUpdateOperatorsMap(
const Operator &op, std::string type, ChunkServerIdType target);
/**
* @brief UpdateOperatorsMap 构造需要导出的operator相关内容,并转化为json格式
*
* @param[in] op, 具体operator
* @param[in] type, operator类型,包含AddPeer/RemovePeer/TransferLeader
* @param[in] target, 变更对象
*/
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_";
// 正在执行的所有operator的数量
bvar::Adder<uint32_t> operatorNum;
// 正在执行的AddPeer operator的数量
bvar::Adder<uint32_t> addOpNum;
// 正在执行的RemovePeer operator的数量
bvar::Adder<uint32_t> removeOpNum;
// 正在执行的TransferLeader operator的数量
bvar::Adder<uint32_t> transferOpNum;
// 正在执行的ChangePeer operator的数量
bvar::Adder<uint32_t> changeOpNum;
// 正在执行的normal级别的operator的数量
bvar::Adder<uint32_t> normalOpNum;
// 正在执行的high级别的operator的数量
bvar::Adder<uint32_t> highOpNum;
// 正在执行的具体的operator
std::map<CopySetKey, StringStatus> operators;
private:
std::shared_ptr<Topology> topo_;
};
} // namespace schedule
} // namespace mds
} // namespace curve
#endif // SRC_MDS_SCHEDULE_SCHEDULEMETRICS_H_