未验证 提交 dd0f7be3 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #5502 from taosdata/fix/TD-3370

[TD-3370]<fix>: fix used disk size, show acctual used instead of non-…
...@@ -163,6 +163,7 @@ extern float tsTotalDataDirGB; ...@@ -163,6 +163,7 @@ extern float tsTotalDataDirGB;
extern float tsAvailLogDirGB; extern float tsAvailLogDirGB;
extern float tsAvailTmpDirectorySpace; extern float tsAvailTmpDirectorySpace;
extern float tsAvailDataDirGB; extern float tsAvailDataDirGB;
extern float tsUsedDataDirGB;
extern float tsMinimalLogDirGB; extern float tsMinimalLogDirGB;
extern float tsReservedTmpDirectorySpace; extern float tsReservedTmpDirectorySpace;
extern float tsMinimalDataDirGB; extern float tsMinimalDataDirGB;
......
...@@ -210,6 +210,7 @@ float tsTotalTmpDirGB = 0; ...@@ -210,6 +210,7 @@ float tsTotalTmpDirGB = 0;
float tsTotalDataDirGB = 0; float tsTotalDataDirGB = 0;
float tsAvailTmpDirectorySpace = 0; float tsAvailTmpDirectorySpace = 0;
float tsAvailDataDirGB = 0; float tsAvailDataDirGB = 0;
float tsUsedDataDirGB = 0;
float tsReservedTmpDirectorySpace = 1.0f; float tsReservedTmpDirectorySpace = 1.0f;
float tsMinimalDataDirGB = 1.0f; float tsMinimalDataDirGB = 1.0f;
int32_t tsTotalMemoryMB = 0; int32_t tsTotalMemoryMB = 0;
......
...@@ -35,6 +35,7 @@ typedef struct { ...@@ -35,6 +35,7 @@ typedef struct {
// FS APIs ==================================== // FS APIs ====================================
typedef struct { typedef struct {
int64_t tsize; int64_t tsize;
int64_t used;
int64_t avail; int64_t avail;
} SFSMeta; } SFSMeta;
...@@ -90,4 +91,4 @@ void tfsClosedir(TDIR *tdir); ...@@ -90,4 +91,4 @@ void tfsClosedir(TDIR *tdir);
} }
#endif #endif
#endif #endif
\ No newline at end of file
...@@ -23,6 +23,7 @@ extern "C" { ...@@ -23,6 +23,7 @@ extern "C" {
// TAOS_OS_FUNC_SYSINFO // TAOS_OS_FUNC_SYSINFO
typedef struct { typedef struct {
int64_t tsize; int64_t tsize;
int64_t used;
int64_t avail; int64_t avail;
} SysDiskSize; } SysDiskSize;
......
...@@ -138,6 +138,8 @@ void taosPrintOsInfo() { ...@@ -138,6 +138,8 @@ void taosPrintOsInfo() {
// uInfo(" os streamMax: %" PRId64, tsStreamMax); // uInfo(" os streamMax: %" PRId64, tsStreamMax);
uInfo(" os numOfCores: %d", tsNumOfCores); uInfo(" os numOfCores: %d", tsNumOfCores);
uInfo(" os totalDisk: %f(GB)", tsTotalDataDirGB); uInfo(" os totalDisk: %f(GB)", tsTotalDataDirGB);
uInfo(" os usedDisk: %f(GB)", tsUsedDataDirGB);
uInfo(" os availDisk: %f(GB)", tsAvailDataDirGB);
uInfo(" os totalMemory: %d(MB)", tsTotalMemoryMB); uInfo(" os totalMemory: %d(MB)", tsTotalMemoryMB);
struct utsname buf; struct utsname buf;
...@@ -222,6 +224,7 @@ int32_t taosGetDiskSize(char *dataDir, SysDiskSize *diskSize) { ...@@ -222,6 +224,7 @@ int32_t taosGetDiskSize(char *dataDir, SysDiskSize *diskSize) {
} else { } else {
diskSize->tsize = info.f_blocks * info.f_frsize; diskSize->tsize = info.f_blocks * info.f_frsize;
diskSize->avail = info.f_bavail * info.f_frsize; diskSize->avail = info.f_bavail * info.f_frsize;
diskSize->used = (info.f_blocks - info.f_bfree) * info.f_frsize;
return 0; return 0;
} }
} }
......
...@@ -326,6 +326,7 @@ int32_t taosGetDiskSize(char *dataDir, SysDiskSize *diskSize) { ...@@ -326,6 +326,7 @@ int32_t taosGetDiskSize(char *dataDir, SysDiskSize *diskSize) {
} else { } else {
diskSize->tsize = info.f_blocks * info.f_frsize; diskSize->tsize = info.f_blocks * info.f_frsize;
diskSize->avail = info.f_bavail * info.f_frsize; diskSize->avail = info.f_bavail * info.f_frsize;
diskSize->used = (info.f_blocks - info.f_bfree) * info.f_frsize;
return 0; return 0;
} }
} }
...@@ -506,6 +507,8 @@ void taosPrintOsInfo() { ...@@ -506,6 +507,8 @@ void taosPrintOsInfo() {
uInfo(" os streamMax: %" PRId64, tsStreamMax); uInfo(" os streamMax: %" PRId64, tsStreamMax);
uInfo(" os numOfCores: %d", tsNumOfCores); uInfo(" os numOfCores: %d", tsNumOfCores);
uInfo(" os totalDisk: %f(GB)", tsTotalDataDirGB); uInfo(" os totalDisk: %f(GB)", tsTotalDataDirGB);
uInfo(" os usedDisk: %f(GB)", tsUsedDataDirGB);
uInfo(" os availDisk: %f(GB)", tsAvailDataDirGB);
uInfo(" os totalMemory: %d(MB)", tsTotalMemoryMB); uInfo(" os totalMemory: %d(MB)", tsTotalMemoryMB);
struct utsname buf; struct utsname buf;
......
...@@ -136,7 +136,8 @@ int32_t taosGetDiskSize(char *dataDir, SysDiskSize *diskSize) { ...@@ -136,7 +136,8 @@ int32_t taosGetDiskSize(char *dataDir, SysDiskSize *diskSize) {
(PULARGE_INTEGER)&i64FreeBytes); (PULARGE_INTEGER)&i64FreeBytes);
if (fResult) { if (fResult) {
diskSize->tsize = (int64_t)(i64TotalBytes); diskSize->tsize = (int64_t)(i64TotalBytes);
diskSize->avail = (int64_t)(i64FreeBytes); diskSize->avail = (int64_t)(i64FreeBytesToCaller);
diskSize->used = (int64_t)(i64TotalBytes - i64FreeBytes);
return 0; return 0;
} else { } else {
uError("failed to get disk size, dataDir:%s errno:%s", tsDataDir, strerror(errno)); uError("failed to get disk size, dataDir:%s errno:%s", tsDataDir, strerror(errno));
...@@ -205,6 +206,8 @@ void taosGetSystemInfo() { ...@@ -205,6 +206,8 @@ void taosGetSystemInfo() {
void taosPrintOsInfo() { void taosPrintOsInfo() {
uInfo(" os numOfCores: %d", tsNumOfCores); uInfo(" os numOfCores: %d", tsNumOfCores);
uInfo(" os totalDisk: %f(GB)", tsTotalDataDirGB); uInfo(" os totalDisk: %f(GB)", tsTotalDataDirGB);
uInfo(" os usedDisk: %f(GB)", tsUsedDataDirGB);
uInfo(" os availDisk: %f(GB)", tsAvailDataDirGB);
uInfo(" os totalMemory: %d(MB)", tsTotalMemoryMB); uInfo(" os totalMemory: %d(MB)", tsTotalMemoryMB);
uInfo("=================================="); uInfo("==================================");
} }
......
...@@ -292,7 +292,7 @@ static int32_t monBuildCpuSql(char *sql) { ...@@ -292,7 +292,7 @@ static int32_t monBuildCpuSql(char *sql) {
// unit is GB // unit is GB
static int32_t monBuildDiskSql(char *sql) { static int32_t monBuildDiskSql(char *sql) {
return sprintf(sql, ", %f, %d", (tsTotalDataDirGB - tsAvailDataDirGB), (int32_t)tsTotalDataDirGB); return sprintf(sql, ", %f, %d", tsUsedDataDirGB, (int32_t)tsTotalDataDirGB);
} }
// unit is Kb // unit is Kb
......
...@@ -41,6 +41,7 @@ extern int fsDebugFlag; ...@@ -41,6 +41,7 @@ extern int fsDebugFlag;
// tdisk.c ====================================================== // tdisk.c ======================================================
typedef struct { typedef struct {
int64_t size; int64_t size;
int64_t used;
int64_t free; int64_t free;
} SDiskMeta; } SDiskMeta;
...@@ -56,6 +57,7 @@ typedef struct SDisk { ...@@ -56,6 +57,7 @@ typedef struct SDisk {
#define DISK_DIR(pd) ((pd)->dir) #define DISK_DIR(pd) ((pd)->dir)
#define DISK_META(pd) ((pd)->dmeta) #define DISK_META(pd) ((pd)->dmeta)
#define DISK_SIZE(pd) ((pd)->dmeta.size) #define DISK_SIZE(pd) ((pd)->dmeta.size)
#define DISK_USED_SIZE(pd) ((pd)->dmeta.used)
#define DISK_FREE_SIZE(pd) ((pd)->dmeta.free) #define DISK_FREE_SIZE(pd) ((pd)->dmeta.free)
SDisk *tfsNewDisk(int level, int id, const char *dir); SDisk *tfsNewDisk(int level, int id, const char *dir);
...@@ -65,6 +67,7 @@ int tfsUpdateDiskInfo(SDisk *pDisk); ...@@ -65,6 +67,7 @@ int tfsUpdateDiskInfo(SDisk *pDisk);
// ttier.c ====================================================== // ttier.c ======================================================
typedef struct { typedef struct {
int64_t size; int64_t size;
int64_t used;
int64_t free; int64_t free;
int16_t nAvailDisks; // # of Available disks int16_t nAvailDisks; // # of Available disks
} STierMeta; } STierMeta;
...@@ -96,4 +99,4 @@ void tfsPosNextId(STier *pTier); ...@@ -96,4 +99,4 @@ void tfsPosNextId(STier *pTier);
} }
#endif #endif
#endif #endif
\ No newline at end of file
...@@ -52,6 +52,7 @@ int tfsUpdateDiskInfo(SDisk *pDisk) { ...@@ -52,6 +52,7 @@ int tfsUpdateDiskInfo(SDisk *pDisk) {
} }
pDisk->dmeta.size = diskSize.tsize; pDisk->dmeta.size = diskSize.tsize;
pDisk->dmeta.used = diskSize.used;
pDisk->dmeta.free = diskSize.avail; pDisk->dmeta.free = diskSize.avail;
return code; return code;
......
...@@ -134,6 +134,7 @@ void tfsUpdateInfo(SFSMeta *pFSMeta) { ...@@ -134,6 +134,7 @@ void tfsUpdateInfo(SFSMeta *pFSMeta) {
tfsUpdateTierInfo(pTier, &tierMeta); tfsUpdateTierInfo(pTier, &tierMeta);
pFSMeta->tsize += tierMeta.size; pFSMeta->tsize += tierMeta.size;
pFSMeta->avail += tierMeta.free; pFSMeta->avail += tierMeta.free;
pFSMeta->used += tierMeta.used;
} }
tfsLock(); tfsLock();
...@@ -585,6 +586,7 @@ void taosGetDisk() { ...@@ -585,6 +586,7 @@ void taosGetDisk() {
if (tscEmbedded) { if (tscEmbedded) {
tfsUpdateInfo(&fsMeta); tfsUpdateInfo(&fsMeta);
tsTotalDataDirGB = (float)(fsMeta.tsize / unit); tsTotalDataDirGB = (float)(fsMeta.tsize / unit);
tsUsedDataDirGB = (float)(fsMeta.used / unit);
tsAvailDataDirGB = (float)(fsMeta.avail / unit); tsAvailDataDirGB = (float)(fsMeta.avail / unit);
} }
......
...@@ -100,6 +100,7 @@ void tfsUpdateTierInfo(STier *pTier, STierMeta *pTierMeta) { ...@@ -100,6 +100,7 @@ void tfsUpdateTierInfo(STier *pTier, STierMeta *pTierMeta) {
continue; continue;
} }
pTierMeta->size += DISK_SIZE(DISK_AT_TIER(pTier, id)); pTierMeta->size += DISK_SIZE(DISK_AT_TIER(pTier, id));
pTierMeta->used += DISK_USED_SIZE(DISK_AT_TIER(pTier, id));
pTierMeta->free += DISK_FREE_SIZE(DISK_AT_TIER(pTier, id)); pTierMeta->free += DISK_FREE_SIZE(DISK_AT_TIER(pTier, id));
pTierMeta->nAvailDisks++; pTierMeta->nAvailDisks++;
} }
...@@ -166,4 +167,4 @@ void tfsPosNextId(STier *pTier) { ...@@ -166,4 +167,4 @@ void tfsPosNextId(STier *pTier) {
} }
pTier->nextid = nextid; pTier->nextid = nextid;
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册