Skip to content

Commit 1bdc65c

Browse files
yubindyilixiaocui
authored andcommitted
CurveBS: curve_ops_tool show space usage of every logicalpool
Signed-off-by: Zhao ZeYu <[email protected]>
1 parent 4a852a2 commit 1bdc65c

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/tools/status_tool.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,17 @@ int StatusTool::SpaceCmd() {
211211
<< ", created file size = "
212212
<< spaceInfo.currentFileSize / mds::kGB
213213
<< "GB(" << createdFileRatio * 100 << "%)" << std::endl;
214+
215+
std::cout << "Every Logicalpool Space info:" << std::endl;
216+
for (const auto &i : spaceInfo.lpoolspaceinfo) {
217+
std::cout << "logicalPool: name = "<< i.second.poolName
218+
<< ", poolid = " << i.first
219+
<< ", total = "<< i.second.totalCapacity / mds::kGB << "GB"
220+
<< ", used = " << i.second.allocatedSize / mds::kGB << "GB"
221+
<< ", left = " << (i.second.totalCapacity -
222+
i.second.allocatedSize) / mds::kGB
223+
<< "GB"<< std::endl;
224+
}
214225
return 0;
215226
}
216227

@@ -1045,7 +1056,9 @@ int StatusTool::GetSpaceInfo(SpaceInfo* spaceInfo) {
10451056
}
10461057
// 从metric获取space信息
10471058
for (const auto& lgPool : lgPools) {
1059+
LogicalpoolSpaceInfo lpinfo;
10481060
std::string poolName = lgPool.logicalpoolname();
1061+
lpinfo.poolName = poolName;
10491062
std::string metricName = GetPoolTotalChunkSizeName(poolName);
10501063
uint64_t size;
10511064
int res = mdsClient_->GetMetric(metricName, &size);
@@ -1054,27 +1067,34 @@ int StatusTool::GetSpaceInfo(SpaceInfo* spaceInfo) {
10541067
return -1;
10551068
}
10561069
spaceInfo->totalChunkSize += size;
1070+
lpinfo.totalChunkSize +=size;
10571071
metricName = GetPoolUsedChunkSizeName(poolName);
10581072
res = mdsClient_->GetMetric(metricName, &size);
10591073
if (res != 0) {
10601074
std::cout << "Get used chunk byte from mds fail!" << std::endl;
10611075
return -1;
10621076
}
10631077
spaceInfo->usedChunkSize += size;
1078+
lpinfo.usedChunkSize += size;
10641079
metricName = GetPoolLogicalCapacityName(poolName);
10651080
res = mdsClient_->GetMetric(metricName, &size);
10661081
if (res != 0) {
10671082
std::cout << "Get logical capacity from mds fail!" << std::endl;
10681083
return -1;
10691084
}
10701085
spaceInfo->totalCapacity += size;
1086+
lpinfo.totalCapacity += size;
10711087
metricName = GetPoolLogicalAllocName(poolName);
10721088
res = mdsClient_->GetMetric(metricName, &size);
10731089
if (res != 0) {
10741090
std::cout << "Get logical alloc size from mds fail!" << std::endl;
10751091
return -1;
10761092
}
10771093
spaceInfo->allocatedSize += size;
1094+
lpinfo.allocatedSize += size;
1095+
spaceInfo->lpoolspaceinfo.insert(
1096+
std::pair<uint32_t, LogicalpoolSpaceInfo>(
1097+
lgPool.logicalpoolid(), lpinfo));
10781098
}
10791099
// 获取RecycleBin的分配大小
10801100
res = mdsClient_->GetAllocatedSize(curve::mds::RECYCLEBINDIR,

src/tools/status_tool.h

+12
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <string>
3333
#include <memory>
3434
#include <map>
35+
#include <unordered_map>
3536
#include "proto/topology.pb.h"
3637
#include "src/common/timeutility.h"
3738
#include "src/mds/common/mds_define.h"
@@ -58,6 +59,16 @@ using curve::mds::topology::ChunkServerInfo;
5859

5960
namespace curve {
6061
namespace tool {
62+
struct LogicalpoolSpaceInfo {
63+
std::string poolName = "";
64+
uint64_t totalChunkSize = 0;
65+
uint64_t usedChunkSize = 0;
66+
// 总体能容纳的文件大小
67+
uint64_t totalCapacity = 0;
68+
// 分配大小
69+
uint64_t allocatedSize = 0;
70+
};
71+
6172
struct SpaceInfo {
6273
uint64_t totalChunkSize = 0;
6374
uint64_t usedChunkSize = 0;
@@ -69,6 +80,7 @@ struct SpaceInfo {
6980
uint64_t recycleAllocSize = 0;
7081
// 系统中存在的文件大小
7182
uint64_t currentFileSize = 0;
83+
std::unordered_map<uint32_t, LogicalpoolSpaceInfo> lpoolspaceinfo;
7284
};
7385

7486
enum class ServiceName {

0 commit comments

Comments
 (0)