提交 c018e918 编写于 作者: S Shengliang Guan

minor changes

上级 6cfff92b
......@@ -34,9 +34,9 @@ typedef struct {
} SDiskSpace;
void taosGetSystemInfo();
bool taosGetEmail(char *email, int32_t maxLen);
bool taosGetOsReleaseName(char *releaseName, int32_t maxLen);
bool taosGetCpuInfo(char *cpuModel, int32_t maxLen, int32_t *numOfCores);
int32_t taosGetEmail(char *email, int32_t maxLen);
int32_t taosGetOsReleaseName(char *releaseName, int32_t maxLen);
int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, int32_t *numOfCores);
int32_t taosGetCpuCores();
bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage);
bool taosGetTotalSysMemoryKB(uint64_t *kb);
......
......@@ -52,12 +52,12 @@ static char* mndBuildTelemetryReport(SMnode* pMnode) {
tjsonAddStringToObject(pJson, "instanceId", clusterName);
tjsonAddDoubleToObject(pJson, "reportVersion", 1);
if (taosGetOsReleaseName(tmp, sizeof(tmp))) {
if (taosGetOsReleaseName(tmp, sizeof(tmp)) == 0) {
tjsonAddStringToObject(pJson, "os", tmp);
}
int32_t numOfCores = 0;
if (taosGetCpuInfo(tmp, sizeof(tmp), &numOfCores)) {
if (taosGetCpuInfo(tmp, sizeof(tmp), &numOfCores) == 0) {
tjsonAddStringToObject(pJson, "cpuModel", tmp);
tjsonAddDoubleToObject(pJson, "numOfCpu", numOfCores);
} else {
......
......@@ -80,7 +80,6 @@ bool taosGetProcMemory(float *memoryUsedMB) {
return true;
}
int32_t taosGetCpuCores() {
SYSTEM_INFO info;
GetSystemInfo(&info);
......@@ -106,7 +105,7 @@ int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize) {
diskSize->used = (int64_t)(i64TotalBytes - i64FreeBytes);
return 0;
} else {
//printf("failed to get disk size, dataDir:%s errno:%s", tsDataDir, strerror(errno));
// printf("failed to get disk size, dataDir:%s errno:%s", tsDataDir, strerror(errno));
terrno = TAOS_SYSTEM_ERROR(errno);
return -1;
}
......@@ -173,12 +172,12 @@ void taosGetSystemInfo() {
}
void taosKillSystem() {
//printf("function taosKillSystem, exit!");
// printf("function taosKillSystem, exit!");
exit(0);
}
int taosSystem(const char *cmd) {
//printf("taosSystem not support");
// printf("taosSystem not support");
return -1;
}
......@@ -241,9 +240,8 @@ char *taosGetCmdlineByPID(int pid) { return ""; }
#include <errno.h>
#include <libproc.h>
void taosKillSystem() {
//printf("function taosKillSystem, exit!");
// printf("function taosKillSystem, exit!");
exit(0);
}
......@@ -300,7 +298,7 @@ bool taosGetSysMemory(float *memoryUsedMB) {
}
int taosSystem(const char *cmd) {
//printf("un support funtion");
// printf("un support funtion");
return -1;
}
......@@ -309,7 +307,7 @@ void taosSetCoreDump() {}
int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize) {
struct statvfs info;
if (statvfs(dataDir, &info)) {
//printf("failed to get disk size, dataDir:%s errno:%s", tsDataDir, strerror(errno));
// printf("failed to get disk size, dataDir:%s errno:%s", tsDataDir, strerror(errno));
terrno = TAOS_SYSTEM_ERROR(errno);
return -1;
} else {
......@@ -404,12 +402,12 @@ bool taosGetProcMemory(float *memoryUsedMB) {
// FILE *fp = fopen(tsProcMemFile, "r");
TdFilePtr pFile = taosOpenFile(tsProcMemFile, TD_FILE_READ | TD_FILE_STREAM);
if (pFile == NULL) {
//printf("open file:%s failed", tsProcMemFile);
// printf("open file:%s failed", tsProcMemFile);
return false;
}
ssize_t _bytes = 0;
char * line = NULL;
char *line = NULL;
while (!taosEOFFile(pFile)) {
_bytes = taosGetLineFile(pFile, &line);
if ((_bytes < 0) || (line == NULL)) {
......@@ -421,7 +419,7 @@ bool taosGetProcMemory(float *memoryUsedMB) {
}
if (line == NULL) {
//printf("read file:%s failed", tsProcMemFile);
// printf("read file:%s failed", tsProcMemFile);
taosCloseFile(&pFile);
return false;
}
......@@ -431,7 +429,7 @@ bool taosGetProcMemory(float *memoryUsedMB) {
sscanf(line, "%s %" PRId64, tmp, &memKB);
*memoryUsedMB = (float)((double)memKB / 1024);
if(line != NULL) tfree(line);
if (line != NULL) tfree(line);
taosCloseFile(&pFile);
return true;
}
......@@ -440,14 +438,14 @@ static bool taosGetSysCpuInfo(SysCpuInfo *cpuInfo) {
// FILE *fp = fopen(tsSysCpuFile, "r");
TdFilePtr pFile = taosOpenFile(tsSysCpuFile, TD_FILE_READ | TD_FILE_STREAM);
if (pFile == NULL) {
//printf("open file:%s failed", tsSysCpuFile);
// printf("open file:%s failed", tsSysCpuFile);
return false;
}
char * line = NULL;
char *line = NULL;
ssize_t _bytes = taosGetLineFile(pFile, &line);
if ((_bytes < 0) || (line == NULL)) {
//printf("read file:%s failed", tsSysCpuFile);
// printf("read file:%s failed", tsSysCpuFile);
taosCloseFile(&pFile);
return false;
}
......@@ -456,7 +454,7 @@ static bool taosGetSysCpuInfo(SysCpuInfo *cpuInfo) {
sscanf(line, "%s %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64, cpu, &cpuInfo->user, &cpuInfo->nice, &cpuInfo->system,
&cpuInfo->idle);
if(line != NULL) tfree(line);
if (line != NULL) tfree(line);
taosCloseFile(&pFile);
return true;
}
......@@ -465,14 +463,14 @@ static bool taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) {
// FILE *fp = fopen(tsProcCpuFile, "r");
TdFilePtr pFile = taosOpenFile(tsProcCpuFile, TD_FILE_READ | TD_FILE_STREAM);
if (pFile == NULL) {
//printf("open file:%s failed", tsProcCpuFile);
// printf("open file:%s failed", tsProcCpuFile);
return false;
}
char * line = NULL;
char *line = NULL;
ssize_t _bytes = taosGetLineFile(pFile, &line);
if ((_bytes < 0) || (line == NULL)) {
//printf("read file:%s failed", tsProcCpuFile);
// printf("read file:%s failed", tsProcCpuFile);
taosCloseFile(&pFile);
return false;
}
......@@ -486,12 +484,11 @@ static bool taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) {
}
}
if(line != NULL) tfree(line);
if (line != NULL) tfree(line);
taosCloseFile(&pFile);
return true;
}
int32_t taosGetCpuCores() { return (int32_t)sysconf(_SC_NPROCESSORS_ONLN); }
bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage) {
......@@ -550,12 +547,12 @@ bool taosGetCardInfo(int64_t *bytes, int64_t *rbytes, int64_t *tbytes) {
// FILE *fp = fopen(tsSysNetFile, "r");
TdFilePtr pFile = taosOpenFile(tsSysNetFile, TD_FILE_READ | TD_FILE_STREAM);
if (pFile == NULL) {
//printf("open file:%s failed", tsSysNetFile);
// printf("open file:%s failed", tsSysNetFile);
return false;
}
ssize_t _bytes = 0;
char * line = NULL;
char *line = NULL;
while (!taosEOFFile(pFile)) {
int64_t o_rbytes = 0;
......@@ -590,7 +587,7 @@ bool taosGetCardInfo(int64_t *bytes, int64_t *rbytes, int64_t *tbytes) {
*bytes += (o_rbytes + o_tbytes);
}
if(line != NULL) tfree(line);
if (line != NULL) tfree(line);
taosCloseFile(&pFile);
return true;
......@@ -636,12 +633,12 @@ bool taosReadProcIO(int64_t *rchars, int64_t *wchars) {
// FILE *fp = fopen(tsProcIOFile, "r");
TdFilePtr pFile = taosOpenFile(tsProcIOFile, TD_FILE_READ | TD_FILE_STREAM);
if (pFile == NULL) {
//printf("open file:%s failed", tsProcIOFile);
// printf("open file:%s failed", tsProcIOFile);
return false;
}
ssize_t _bytes = 0;
char * line = NULL;
char *line = NULL;
char tmp[10];
int readIndex = 0;
......@@ -662,11 +659,11 @@ bool taosReadProcIO(int64_t *rchars, int64_t *wchars) {
if (readIndex >= 2) break;
}
if(line != NULL) tfree(line);
if (line != NULL) tfree(line);
taosCloseFile(&pFile);
if (readIndex < 2) {
//printf("read file:%s failed", tsProcIOFile);
// printf("read file:%s failed", tsProcIOFile);
return false;
}
......@@ -713,12 +710,11 @@ void taosGetSystemInfo() {
taosGetBandSpeed(&tmp1);
taosGetCpuUsage(&tmp1, &tmp2);
taosGetProcIO(&tmp1, &tmp2);
}
void taosKillSystem() {
// SIGINT
//printf("taosd will shut down soon");
// printf("taosd will shut down soon");
kill(tsProcId, 2);
}
......@@ -727,22 +723,22 @@ int taosSystem(const char *cmd) {
int res;
char buf[1024];
if (cmd == NULL) {
//printf("taosSystem cmd is NULL!");
// printf("taosSystem cmd is NULL!");
return -1;
}
if ((fp = popen(cmd, "r")) == NULL) {
//printf("popen cmd:%s error: %s", cmd, strerror(errno));
// printf("popen cmd:%s error: %s", cmd, strerror(errno));
return -1;
} else {
while (fgets(buf, sizeof(buf), fp)) {
//printf("popen result:%s", buf);
// printf("popen result:%s", buf);
}
if ((res = pclose(fp)) == -1) {
//printf("close popen file pointer fp error!");
// printf("close popen file pointer fp error!");
} else {
//printf("popen res is :%d", res);
// printf("popen res is :%d", res);
}
return res;
......@@ -757,14 +753,14 @@ void taosSetCoreDump(bool enable) {
struct rlimit rlim_new;
if (getrlimit(RLIMIT_CORE, &rlim) == 0) {
#ifndef _ALPINE
//printf("the old unlimited para: rlim_cur=%" PRIu64 ", rlim_max=%" PRIu64, rlim.rlim_cur, rlim.rlim_max);
// printf("the old unlimited para: rlim_cur=%" PRIu64 ", rlim_max=%" PRIu64, rlim.rlim_cur, rlim.rlim_max);
#else
//printf("the old unlimited para: rlim_cur=%llu, rlim_max=%llu", rlim.rlim_cur, rlim.rlim_max);
// printf("the old unlimited para: rlim_cur=%llu, rlim_max=%llu", rlim.rlim_cur, rlim.rlim_max);
#endif
rlim_new.rlim_cur = RLIM_INFINITY;
rlim_new.rlim_max = RLIM_INFINITY;
if (setrlimit(RLIMIT_CORE, &rlim_new) != 0) {
//printf("set unlimited fail, error: %s", strerror(errno));
// printf("set unlimited fail, error: %s", strerror(errno));
rlim_new.rlim_cur = rlim.rlim_max;
rlim_new.rlim_max = rlim.rlim_max;
(void)setrlimit(RLIMIT_CORE, &rlim_new);
......@@ -773,9 +769,9 @@ void taosSetCoreDump(bool enable) {
if (getrlimit(RLIMIT_CORE, &rlim) == 0) {
#ifndef _ALPINE
//printf("the new unlimited para: rlim_cur=%" PRIu64 ", rlim_max=%" PRIu64, rlim.rlim_cur, rlim.rlim_max);
// printf("the new unlimited para: rlim_cur=%" PRIu64 ", rlim_max=%" PRIu64, rlim.rlim_cur, rlim.rlim_max);
#else
//printf("the new unlimited para: rlim_cur=%llu, rlim_max=%llu", rlim.rlim_cur, rlim.rlim_max);
// printf("the new unlimited para: rlim_cur=%llu, rlim_max=%llu", rlim.rlim_cur, rlim.rlim_max);
#endif
}
......@@ -801,10 +797,10 @@ void taosSetCoreDump(bool enable) {
old_len = sizeof(old_usespid);
if (syscall(SYS__sysctl, &args) == -1) {
//printf("_sysctl(kern_core_uses_pid) set fail: %s", strerror(errno));
// printf("_sysctl(kern_core_uses_pid) set fail: %s", strerror(errno));
}
//printf("The old core_uses_pid[%" PRIu64 "]: %d", old_len, old_usespid);
// printf("The old core_uses_pid[%" PRIu64 "]: %d", old_len, old_usespid);
old_usespid = 0;
old_len = 0;
......@@ -817,10 +813,10 @@ void taosSetCoreDump(bool enable) {
old_len = sizeof(old_usespid);
if (syscall(SYS__sysctl, &args) == -1) {
//printf("_sysctl(kern_core_uses_pid) get fail: %s", strerror(errno));
// printf("_sysctl(kern_core_uses_pid) get fail: %s", strerror(errno));
}
//printf("The new core_uses_pid[%" PRIu64 "]: %d", old_len, old_usespid);
// printf("The new core_uses_pid[%" PRIu64 "]: %d", old_len, old_usespid);
#endif
}
......@@ -885,7 +881,7 @@ SysNameInfo taosGetSysNameInfo() {
return info;
}
bool taosGetEmail(char *email, int32_t maxLen) {
int32_t taosGetEmail(char *email, int32_t maxLen) {
const char *filepath = "/usr/local/taos/email";
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ);
......@@ -893,17 +889,17 @@ bool taosGetEmail(char *email, int32_t maxLen) {
if (taosReadFile(pFile, (void *)email, maxLen) < 0) {
taosCloseFile(&pFile);
return false;
return -1;
}
taosCloseFile(&pFile);
return true;
return 0;
}
bool taosGetOsReleaseName(char *releaseName, int32_t maxLen) {
char *line = NULL;
size_t size = 0;
bool ret = false;
int32_t taosGetOsReleaseName(char *releaseName, int32_t maxLen) {
char *line = NULL;
size_t size = 0;
int32_t code = -1;
TdFilePtr pFile = taosOpenFile("/etc/os-release", TD_FILE_READ | TD_FILE_STREAM);
if (pFile == NULL) return false;
......@@ -917,21 +913,21 @@ bool taosGetOsReleaseName(char *releaseName, int32_t maxLen) {
line[size - 2] = 0;
}
tstrncpy(releaseName, p, maxLen);
ret = true;
code = 0;
break;
}
}
if (line != NULL) free(line);
taosCloseFile(&pFile);
return ret;
return code;
}
bool taosGetCpuInfo(char *cpuModel, int32_t maxLen, int32_t *numOfCores) {
int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, int32_t *numOfCores) {
char *line = NULL;
size_t size = 0;
int32_t done = 0;
bool ret = false;
int32_t code = -1;
TdFilePtr pFile = taosOpenFile("/proc/cpuinfo", TD_FILE_READ | TD_FILE_STREAM);
if (pFile == NULL) return false;
......@@ -941,7 +937,7 @@ bool taosGetCpuInfo(char *cpuModel, int32_t maxLen, int32_t *numOfCores) {
if (((done & 1) == 0) && strncmp(line, "model name", 10) == 0) {
const char *v = strchr(line, ':') + 2;
tstrncpy(cpuModel, v, maxLen);
ret = true;
code = 0;
done |= 1;
} else if (((done & 2) == 0) && strncmp(line, "cpu cores", 9) == 0) {
const char *v = strchr(line, ':') + 2;
......@@ -953,7 +949,7 @@ bool taosGetCpuInfo(char *cpuModel, int32_t maxLen, int32_t *numOfCores) {
if (line != NULL) free(line);
taosCloseFile(&pFile);
return ret;
return code;
}
bool taosGetTotalSysMemoryKB(uint64_t *kb) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册