This commit is contained in:
Shengliang Guan 2020-10-26 10:47:46 +08:00
parent f17ec44e46
commit 382adfac68
11 changed files with 47 additions and 95 deletions

View File

@ -17,7 +17,6 @@
#include "taosmsg.h"
#include "tcache.h"
#include "trpc.h"
#include "tsystem.h"
#include "ttimer.h"
#include "tutil.h"
#include "tsched.h"

View File

@ -1,38 +0,0 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_TSYSTEM_H
#define TDENGINE_TSYSTEM_H
#ifdef __cplusplus
extern "C" {
#endif
bool taosGetSysMemory(float *memoryUsedMB);
bool taosGetProcMemory(float *memoryUsedMB);
bool taosGetDisk();
bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage);
bool taosGetBandSpeed(float *bandSpeedKb);
bool taosGetProcIO(float *readKB, float *writeKB);
void taosGetSystemInfo();
void taosPrintOsInfo();
void taosKillSystem();
void taosSetCoreDump();
#ifdef __cplusplus
}
#endif
#endif

View File

@ -244,15 +244,15 @@ static int tdCheckDisk(char *dirName, int level, int primary) {
}
static int tdUpdateDiskMeta(SDisk *pDisk) {
struct statvfs dstat;
if (statvfs(pDisk->dir, &dstat) < 0) {
SysDiskSize dstat;
if (taosGetDiskSize(pDisk->dir, &dstat) < 0) {
uError("failed to get dir %s information since %s", pDisk->dir, strerror(errno));
terrno = TAOS_SYSTEM_ERROR(errno);
return -1;
}
pDisk->dmeta.size = dstat.f_bsize * dstat.f_blocks;
pDisk->dmeta.free = dstat.f_bsize * dstat.f_bavail;
pDisk->dmeta.size = dstat.tsize;
pDisk->dmeta.free = dstat.avail;
return 0;
}
@ -350,3 +350,24 @@ static int tdAddDisk(SDnodeTier *pDnodeTier, char *dir, int level, int primary)
return 0;
}
void taosGetDisk() {
const double unit = 1024 * 1024 * 1024;
SysDiskSize diskSize;
if (tscEmbedded) {
tdUpdateTiersInfo(tsDnodeTier);
tsTotalDataDirGB = (float)tsDnodeTier->meta.tsize / unit;
tsAvailDataDirGB = (float)tsDnodeTier->meta.avail / unit;
}
if (taosGetDiskSize(tsLogDir, &diskSize)) {
tsTotalLogDirGB = (float)diskSize.tsize / unit;
tsAvailLogDirGB = (float)diskSize.avail / unit;
}
if (taosGetDiskSize("/tmp", &diskSize)) {
tsTotalTmpDirGB = (float)diskSize.tsize / unit;
tsAvailTmpDirectorySpace = (float)diskSize.avail / unit;
}
}

View File

@ -17,7 +17,6 @@
#include "os.h"
#include "taoserror.h"
#include "tsched.h"
#include "tsystem.h"
#include "tutil.h"
#include "tgrant.h"
#include "tbalance.h"

View File

@ -21,10 +21,16 @@ extern "C" {
#endif
// TAOS_OS_FUNC_SYSINFO
typedef struct {
int64_t tsize;
int64_t avail;
} SysDiskSize;
int32_t taosGetDiskSize(char *dataDir, SysDiskSize *diskSize);
void taosGetSystemInfo();
bool taosGetProcIO(float *readKB, float *writeKB);
bool taosGetBandSpeed(float *bandSpeedKb);
bool taosGetDisk();
void taosGetDisk();
bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage) ;
bool taosGetProcMemory(float *memoryUsedMB) ;
bool taosGetSysMemory(float *memoryUsedMB);

View File

@ -67,7 +67,7 @@ void taosGetSystemInfo() {
taosGetSystemLocale();
}
bool taosGetDisk() { return true; }
void taosGetDisk() {}
bool taosGetProcIO(float *readKB, float *writeKB) {
*readKB = 0;

View File

@ -16,6 +16,7 @@
#define _DEFAULT_SOURCE
#include "os.h"
#include "tconfig.h"
#include "tdisk.h"
#include "tglobal.h"
#include "tulog.h"
@ -297,46 +298,17 @@ bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage) {
return true;
}
bool taosGetDisk() {
int32_t taosGetDiskSize(char *dataDir, SysDiskSize *diskSize) {
struct statvfs info;
const double unit = 1024 * 1024 * 1024;
#if 0
if (tscEmbedded) {
if (statvfs(tsDataDir, &info)) {
//tsTotalDataDirGB = 0;
//tsAvailDataDirGB = 0;
uError("failed to get disk size, dataDir:%s errno:%s", tsDataDir, strerror(errno));
return false;
} else {
tsTotalDataDirGB = (float)((double)info.f_blocks * (double)info.f_frsize / unit);
tsAvailDataDirGB = (float)((double)info.f_bavail * (double)info.f_frsize / unit);
}
}
#endif
if (statvfs(tsLogDir, &info)) {
//tsTotalLogDirGB = 0;
//tsAvailLogDirGB = 0;
uError("failed to get disk size, logDir:%s errno:%s", tsLogDir, strerror(errno));
return false;
} else {
tsTotalLogDirGB = (float)((double)info.f_blocks * (double)info.f_frsize / unit);
tsAvailLogDirGB = (float)((double)info.f_bavail * (double)info.f_frsize / unit);
}
if (statvfs("/tmp", &info)) {
//tsTotalTmpDirGB = 0;
//tsAvailTmpDirectorySpace = 0;
uError("failed to get disk size, tmpDir:/tmp errno:%s", strerror(errno));
return false;
} else {
tsTotalTmpDirGB = (float)((double)info.f_blocks * (double)info.f_frsize / unit);
tsAvailTmpDirectorySpace = (float)((double)info.f_bavail * (double)info.f_frsize / unit);
}
diskSize->tsize = info.f_blocks * info.f_frsize;
diskSize->avail = info.f_bavail * info.f_frsize;
return true;
}
}
static bool taosGetCardInfo(int64_t *bytes) {
*bytes = 0;
@ -508,7 +480,7 @@ void taosGetSystemInfo() {
float tmp1, tmp2;
taosGetSysMemory(&tmp1);
taosGetProcMemory(&tmp2);
taosGetDisk();
// taosGetDisk();
taosGetBandSpeed(&tmp1);
taosGetCpuUsage(&tmp1, &tmp2);
taosGetProcIO(&tmp1, &tmp2);

View File

@ -80,7 +80,7 @@ void taosGetSystemInfo() {
taosGetSystemLocale();
}
bool taosGetDisk() {
void taosGetDisk() {
const double unit = 1024 * 1024 * 1024;
BOOL fResult;
unsigned _int64 i64FreeBytesToCaller;

View File

@ -21,7 +21,6 @@
#include "ttimer.h"
#include "tutil.h"
#include "tdisk.h"
#include "tsystem.h"
#include "tscUtil.h"
#include "tsclient.h"
#include "dnode.h"
@ -126,10 +125,6 @@ static void *monitorThreadFunc(void *param) {
break;
} else {
taosGetDisk();
tdUpdateTiersInfo(tsDnodeTier);
const double unit = 1024 * 1024 * 1024;
tsTotalDataDirGB = tsDnodeTier->meta.tsize / unit;
tsAvailDataDirGB = tsDnodeTier->meta.avail / unit;
}
if (tsMonitor.start == 0) {

View File

@ -15,7 +15,6 @@
#include "os.h"
#include "tsocket.h"
#include "tsystem.h"
#include "ttimer.h"
#include "tutil.h"
#include "taosdef.h"

View File

@ -22,7 +22,6 @@
#include "tkey.h"
#include "tulog.h"
#include "tsocket.h"
#include "tsystem.h"
#include "tutil.h"
SGlobalCfg tsGlobalConfig[TSDB_CFG_MAX_NUM] = {{0}};