minor changes

This commit is contained in:
Shengliang Guan 2022-03-03 17:30:33 +08:00
parent 6cfff92b21
commit c018e91859
3 changed files with 58 additions and 62 deletions

View File

@ -34,9 +34,9 @@ typedef struct {
} SDiskSpace; } SDiskSpace;
void taosGetSystemInfo(); void taosGetSystemInfo();
bool taosGetEmail(char *email, int32_t maxLen); int32_t taosGetEmail(char *email, int32_t maxLen);
bool taosGetOsReleaseName(char *releaseName, int32_t maxLen); int32_t taosGetOsReleaseName(char *releaseName, int32_t maxLen);
bool taosGetCpuInfo(char *cpuModel, int32_t maxLen, int32_t *numOfCores); int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, int32_t *numOfCores);
int32_t taosGetCpuCores(); int32_t taosGetCpuCores();
bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage); bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage);
bool taosGetTotalSysMemoryKB(uint64_t *kb); bool taosGetTotalSysMemoryKB(uint64_t *kb);

View File

@ -52,12 +52,12 @@ static char* mndBuildTelemetryReport(SMnode* pMnode) {
tjsonAddStringToObject(pJson, "instanceId", clusterName); tjsonAddStringToObject(pJson, "instanceId", clusterName);
tjsonAddDoubleToObject(pJson, "reportVersion", 1); tjsonAddDoubleToObject(pJson, "reportVersion", 1);
if (taosGetOsReleaseName(tmp, sizeof(tmp))) { if (taosGetOsReleaseName(tmp, sizeof(tmp)) == 0) {
tjsonAddStringToObject(pJson, "os", tmp); tjsonAddStringToObject(pJson, "os", tmp);
} }
int32_t numOfCores = 0; int32_t numOfCores = 0;
if (taosGetCpuInfo(tmp, sizeof(tmp), &numOfCores)) { if (taosGetCpuInfo(tmp, sizeof(tmp), &numOfCores) == 0) {
tjsonAddStringToObject(pJson, "cpuModel", tmp); tjsonAddStringToObject(pJson, "cpuModel", tmp);
tjsonAddDoubleToObject(pJson, "numOfCpu", numOfCores); tjsonAddDoubleToObject(pJson, "numOfCpu", numOfCores);
} else { } else {

View File

@ -80,7 +80,6 @@ bool taosGetProcMemory(float *memoryUsedMB) {
return true; return true;
} }
int32_t taosGetCpuCores() { int32_t taosGetCpuCores() {
SYSTEM_INFO info; SYSTEM_INFO info;
GetSystemInfo(&info); GetSystemInfo(&info);
@ -241,7 +240,6 @@ char *taosGetCmdlineByPID(int pid) { return ""; }
#include <errno.h> #include <errno.h>
#include <libproc.h> #include <libproc.h>
void taosKillSystem() { void taosKillSystem() {
// printf("function taosKillSystem, exit!"); // printf("function taosKillSystem, exit!");
exit(0); exit(0);
@ -491,7 +489,6 @@ static bool taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) {
return true; return true;
} }
int32_t taosGetCpuCores() { return (int32_t)sysconf(_SC_NPROCESSORS_ONLN); } int32_t taosGetCpuCores() { return (int32_t)sysconf(_SC_NPROCESSORS_ONLN); }
bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage) { bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage) {
@ -713,7 +710,6 @@ void taosGetSystemInfo() {
taosGetBandSpeed(&tmp1); taosGetBandSpeed(&tmp1);
taosGetCpuUsage(&tmp1, &tmp2); taosGetCpuUsage(&tmp1, &tmp2);
taosGetProcIO(&tmp1, &tmp2); taosGetProcIO(&tmp1, &tmp2);
} }
void taosKillSystem() { void taosKillSystem() {
@ -885,7 +881,7 @@ SysNameInfo taosGetSysNameInfo() {
return info; return info;
} }
bool taosGetEmail(char *email, int32_t maxLen) { int32_t taosGetEmail(char *email, int32_t maxLen) {
const char *filepath = "/usr/local/taos/email"; const char *filepath = "/usr/local/taos/email";
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ); 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) { if (taosReadFile(pFile, (void *)email, maxLen) < 0) {
taosCloseFile(&pFile); taosCloseFile(&pFile);
return false; return -1;
} }
taosCloseFile(&pFile); taosCloseFile(&pFile);
return true; return 0;
} }
bool taosGetOsReleaseName(char *releaseName, int32_t maxLen) { int32_t taosGetOsReleaseName(char *releaseName, int32_t maxLen) {
char *line = NULL; char *line = NULL;
size_t size = 0; size_t size = 0;
bool ret = false; int32_t code = -1;
TdFilePtr pFile = taosOpenFile("/etc/os-release", TD_FILE_READ | TD_FILE_STREAM); TdFilePtr pFile = taosOpenFile("/etc/os-release", TD_FILE_READ | TD_FILE_STREAM);
if (pFile == NULL) return false; if (pFile == NULL) return false;
@ -917,21 +913,21 @@ bool taosGetOsReleaseName(char *releaseName, int32_t maxLen) {
line[size - 2] = 0; line[size - 2] = 0;
} }
tstrncpy(releaseName, p, maxLen); tstrncpy(releaseName, p, maxLen);
ret = true; code = 0;
break; break;
} }
} }
if (line != NULL) free(line); if (line != NULL) free(line);
taosCloseFile(&pFile); 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; char *line = NULL;
size_t size = 0; size_t size = 0;
int32_t done = 0; int32_t done = 0;
bool ret = false; int32_t code = -1;
TdFilePtr pFile = taosOpenFile("/proc/cpuinfo", TD_FILE_READ | TD_FILE_STREAM); TdFilePtr pFile = taosOpenFile("/proc/cpuinfo", TD_FILE_READ | TD_FILE_STREAM);
if (pFile == NULL) return false; 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) { if (((done & 1) == 0) && strncmp(line, "model name", 10) == 0) {
const char *v = strchr(line, ':') + 2; const char *v = strchr(line, ':') + 2;
tstrncpy(cpuModel, v, maxLen); tstrncpy(cpuModel, v, maxLen);
ret = true; code = 0;
done |= 1; done |= 1;
} else if (((done & 2) == 0) && strncmp(line, "cpu cores", 9) == 0) { } else if (((done & 2) == 0) && strncmp(line, "cpu cores", 9) == 0) {
const char *v = strchr(line, ':') + 2; 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); if (line != NULL) free(line);
taosCloseFile(&pFile); taosCloseFile(&pFile);
return ret; return code;
} }
bool taosGetTotalSysMemoryKB(uint64_t *kb) { bool taosGetTotalSysMemoryKB(uint64_t *kb) {