Skip to content

Commit 01e00d8

Browse files
committed
curvebs/mds: add curvebs logicpool io metric
1 parent 0fd8cc8 commit 01e00d8

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

src/mds/topology/topology_metric.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ void TopologyMetricService::UpdateTopologyMetrics() {
4444
return cs.GetStatus() != ChunkServerStatus::RETIRED;
4545
});
4646

47+
std::vector<CopysetStat> copysetStatsCs, copysetStatsCluster;
4748
for (auto csId : chunkservers) {
4849
auto it = gChunkServerMetrics.find(csId);
4950
if (it == gChunkServerMetrics.end()) {
@@ -84,6 +85,11 @@ void TopologyMetricService::UpdateTopologyMetrics() {
8485
csStat.chunkSizeLeftBytes +
8586
csStat.chunkSizeTrashedBytes);
8687
}
88+
89+
copysetStatsCs = csStat.copysetStats;
90+
copysetStatsCluster.insert(copysetStatsCluster.end(),
91+
copysetStatsCs.begin(), copysetStatsCs.end());
92+
copysetStatsCs.clear();
8793
}
8894

8995
// process logical pool
@@ -209,7 +215,36 @@ void TopologyMetricService::UpdateTopologyMetrics() {
209215
it->second->logicalCapacity.set_value(
210216
totalChunkSizeBytes / pool.GetReplicaNum());
211217
}
218+
219+
uint64_t readRate = 0, writeRate = 0,
220+
readIOPS = 0, writeIOPS = 0;
221+
for (auto iterCsStat : copysetStatsCluster) {
222+
if (iterCsStat.logicalPoolId == pid) {
223+
readRate += iterCsStat.readRate;
224+
writeRate += iterCsStat.writeRate;
225+
readIOPS += iterCsStat.readIOPS;
226+
writeIOPS += iterCsStat.writeIOPS;
227+
}
228+
DVLOG(6) << "copyset Metrics, csid is: "
229+
<< iterCsStat.copysetId << ", write iops: "
230+
<< iterCsStat.writeIOPS << ", write bps: "
231+
<< iterCsStat.writeRate << ", read bps: "
232+
<< iterCsStat.readRate << ", read iops: "
233+
<< iterCsStat.readIOPS;
234+
}
235+
it->second->writeIOPS.set_value(writeIOPS);
236+
it->second->writeRate.set_value(writeRate);
237+
it->second->readRate.set_value(readRate);
238+
it->second->readIOPS.set_value(readIOPS);
239+
240+
DVLOG(6) << "pool metrics, pid is: "
241+
<< pid << ", write iops: "
242+
<< writeIOPS << ", write bps: "
243+
<< writeRate << ", read bps: "
244+
<< readRate << ", read iops: "
245+
<< readIOPS;
212246
}
247+
213248
// remove logical pool metrics that no longer exist
214249
for (auto iy = gLogicalPoolMetrics.begin();
215250
iy != gLogicalPoolMetrics.end();) {

src/mds/topology/topology_metric.h

+19-1
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,15 @@ struct LogicalPoolMetric {
176176
// bytes have alloced
177177
bvar::Status<uint64_t> logicalAlloc;
178178

179+
// bandwidth of reading
180+
bvar::Status<uint64_t> readRate;
181+
// bandwidth of writing
182+
bvar::Status<uint64_t> writeRate;
183+
// IOPS of reading
184+
bvar::Status<uint64_t> readIOPS;
185+
// IOPS of writing
186+
bvar::Status<uint64_t> writeIOPS;
187+
179188
explicit LogicalPoolMetric(const std::string &logicalPoolName) :
180189
chunkServerNum(kTopologyLogicalPoolMetricPrefix,
181190
logicalPoolName + "_chunkserver_num", 0),
@@ -234,7 +243,16 @@ struct LogicalPoolMetric {
234243
logicalCapacity(kTopologyLogicalPoolMetricPrefix,
235244
logicalPoolName + "_logicalCapacity", 0),
236245
logicalAlloc(kTopologyLogicalPoolMetricPrefix,
237-
logicalPoolName + "_logicalAlloc", 0) {}
246+
logicalPoolName + "_logicalAlloc", 0),
247+
readRate(kTopologyLogicalPoolMetricPrefix,
248+
logicalPoolName + "_readRate", 0),
249+
writeRate(kTopologyLogicalPoolMetricPrefix,
250+
logicalPoolName + "_writeRate", 0),
251+
readIOPS(kTopologyLogicalPoolMetricPrefix,
252+
logicalPoolName + "_readIOPS", 0),
253+
writeIOPS(kTopologyLogicalPoolMetricPrefix,
254+
logicalPoolName + "_writeIOPS", 0)
255+
{}
238256
};
239257
using LogicalPoolMetricPtr = std::unique_ptr<LogicalPoolMetric>;
240258

test/mds/topology/test_topology_metric.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,11 @@ TEST_F(TestTopologyMetric, TestUpdateTopologyMetricsOneLogicalPool) {
339339
gLogicalPoolMetrics[logicalPoolId]->chunkSizeTrashedBytes.get_value());
340340
ASSERT_EQ(1024 * 9,
341341
gLogicalPoolMetrics[logicalPoolId]->chunkSizeTotalBytes.get_value());
342+
343+
ASSERT_EQ(3, gLogicalPoolMetrics[logicalPoolId]->readIOPS.get_value());
344+
ASSERT_EQ(3, gLogicalPoolMetrics[logicalPoolId]->writeIOPS.get_value());
345+
ASSERT_EQ(3, gLogicalPoolMetrics[logicalPoolId]->readRate.get_value());
346+
ASSERT_EQ(3, gLogicalPoolMetrics[logicalPoolId]->writeRate.get_value());
342347
}
343348

344349
TEST_F(TestTopologyMetric, TestUpdateTopologyMetricsCleanRetired) {

0 commit comments

Comments
 (0)