From 2bf46ddc54a1282620b4ad725f2a94a68c95008c Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 3 Mar 2022 19:12:08 +0800 Subject: [PATCH] monitor --- include/libs/monitor/monitor.h | 12 ++++----- include/os/osSysinfo.h | 4 +-- source/dnode/mgmt/impl/inc/dndMnode.h | 1 + source/dnode/mgmt/impl/src/dndMgmt.c | 33 +++++++++++------------ source/dnode/mgmt/impl/src/dndMnode.c | 7 +++++ source/os/src/osSysinfo.c | 38 +++++++++++++-------------- 6 files changed, 51 insertions(+), 44 deletions(-) diff --git a/include/libs/monitor/monitor.h b/include/libs/monitor/monitor.h index 487b2bfe88..00cb7c3dbc 100644 --- a/include/libs/monitor/monitor.h +++ b/include/libs/monitor/monitor.h @@ -94,12 +94,12 @@ typedef struct { float disk_engine; // GB float disk_used; // GB float disk_total; // GB - float net_in; // Kb/s - float net_out; // Kb/s - float io_read; // Mb/s - float io_write; // Mb/s - float io_read_disk; // Mb/s - float io_write_disk; // Mb/s + int64_t net_in; + int64_t net_out; + float io_read; + float io_write; + float io_read_disk; + float io_write_disk; int32_t req_select; float req_select_rate; int32_t req_insert; diff --git a/include/os/osSysinfo.h b/include/os/osSysinfo.h index 3c68615c64..e14dba8269 100644 --- a/include/os/osSysinfo.h +++ b/include/os/osSysinfo.h @@ -45,8 +45,8 @@ int32_t taosGetSysMemory(int64_t *usedKB); int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize); int32_t taosReadProcIO(int64_t *rchars, int64_t *wchars); int32_t taosGetProcIO(float *readKB, float *writeKB); -bool taosGetCardInfo(int64_t *bytes, int64_t *rbytes, int64_t *tbytes); -bool taosGetBandSpeed(float *bandSpeedKb); +int32_t taosGetCardInfo(int64_t *bytes, int64_t *rbytes, int64_t *tbytes); +int32_t taosGetBandSpeed(float *bandSpeedKb); int32_t taosSystem(const char *cmd); void taosKillSystem(); diff --git a/source/dnode/mgmt/impl/inc/dndMnode.h b/source/dnode/mgmt/impl/inc/dndMnode.h index 0f03bb3832..0aee3b4b43 100644 --- a/source/dnode/mgmt/impl/inc/dndMnode.h +++ b/source/dnode/mgmt/impl/inc/dndMnode.h @@ -34,6 +34,7 @@ int32_t dndProcessDropMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg); int32_t dndGetMnodeMonitorInfo(SDnode *pDnode, SMonClusterInfo *pClusterInfo, SMonVgroupInfo *pVgroupInfo, SMonGrantInfo *pGrantInfo); +int8_t dndIsMnode(SDnode *pDnode); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/impl/src/dndMgmt.c b/source/dnode/mgmt/impl/src/dndMgmt.c index 6a743fcf48..60cfdc299c 100644 --- a/source/dnode/mgmt/impl/src/dndMgmt.c +++ b/source/dnode/mgmt/impl/src/dndMgmt.c @@ -486,26 +486,25 @@ static void dndGetMonitorDnodeInfo(SDnode *pDnode, SMonDnodeInfo *pInfo) { taosGetProcMemory(&pInfo->mem_engine); taosGetSysMemory(&pInfo->mem_system); pInfo->mem_total = tsTotalMemoryKB; - pInfo->disk_engine = 4.1; - pInfo->disk_used = 4.2; - pInfo->disk_total = 4.3; - pInfo->net_in = 5.1; - pInfo->net_out = 5.2; + pInfo->disk_engine = 0; + pInfo->disk_used = tsDataSpace.size.used / (1024 * 1024 * 1024.0); + pInfo->disk_total = tsDataSpace.size.avail / (1024 * 1024 * 1024.0); + taosGetCardInfo(NULL, &pInfo->net_in, &pInfo->net_out); taosGetProcIO(&pInfo->io_read, &pInfo->io_write); pInfo->io_read_disk = 0; pInfo->io_write_disk = 0; - pInfo->req_select = 8; - pInfo->req_select_rate = 8.1; - pInfo->req_insert = 9; - pInfo->req_insert_success = 10; - pInfo->req_insert_rate = 10.1; - pInfo->req_insert_batch = 11; - pInfo->req_insert_batch_success = 12; - pInfo->req_insert_batch_rate = 12.3; - pInfo->errors = 4; - pInfo->vnodes_num = 5; - pInfo->masters = 6; - pInfo->has_mnode = 1; + pInfo->req_select = 0; + pInfo->req_select_rate = 0; + pInfo->req_insert = 0; + pInfo->req_insert_success = 0; + pInfo->req_insert_rate = 0; + pInfo->req_insert_batch = 0; + pInfo->req_insert_batch_success = 0; + pInfo->req_insert_batch_rate = 0; + pInfo->errors = 0; + pInfo->vnodes_num = 0; + pInfo->masters = 0; + pInfo->has_mnode = dndIsMnode(pDnode); } static void dndSendMonitorReport(SDnode *pDnode) { diff --git a/source/dnode/mgmt/impl/src/dndMnode.c b/source/dnode/mgmt/impl/src/dndMnode.c index 6cb117867f..47e74b5c57 100644 --- a/source/dnode/mgmt/impl/src/dndMnode.c +++ b/source/dnode/mgmt/impl/src/dndMnode.c @@ -639,4 +639,11 @@ int32_t dndGetMnodeMonitorInfo(SDnode *pDnode, SMonClusterInfo *pClusterInfo, SM int32_t code = mndGetMonitorInfo(pMnode, pClusterInfo, pVgroupInfo, pGrantInfo); dndReleaseMnode(pDnode, pMnode); return code; +} + +int8_t dndIsMnode(SDnode *pDnode) { + SMnode *pMnode = dndAcquireMnode(pDnode); + if (pMnode == NULL) return 0; + dndReleaseMnode(pDnode, pMnode); + return 1; } \ No newline at end of file diff --git a/source/os/src/osSysinfo.c b/source/os/src/osSysinfo.c index 3683943c61..c674aeaca2 100644 --- a/source/os/src/osSysinfo.c +++ b/source/os/src/osSysinfo.c @@ -112,16 +112,16 @@ int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize) { } } -bool taosGetCardInfo(int64_t *bytes, int64_t *rbytes, int64_t *tbytes) { +int32_t taosGetCardInfo(int64_t *bytes, int64_t *rbytes, int64_t *tbytes) { if (bytes) *bytes = 0; if (rbytes) *rbytes = 0; if (tbytes) *tbytes = 0; - return true; + return 0; } -bool taosGetBandSpeed(float *bandSpeedKb) { +int32_t taosGetBandSpeed(float *bandSpeedKb) { *bandSpeedKb = 0; - return true; + return 0; } int32_t taosReadProcIO(int64_t *readbyte, int64_t *writebyte) { @@ -271,16 +271,16 @@ int32_t taosGetProcIO(float *readKB, float *writeKB) { return 0; } -bool taosGetCardInfo(int64_t *bytes, int64_t *rbytes, int64_t *tbytes) { +int32_t taosGetCardInfo(int64_t *bytes, int64_t *rbytes, int64_t *tbytes) { if (bytes) *bytes = 0; if (rbytes) *rbytes = 0; if (tbytes) *tbytes = 0; - return true; + return 0; } -bool taosGetBandSpeed(float *bandSpeedKb) { +int32_t taosGetBandSpeed(float *bandSpeedKb) { *bandSpeedKb = 0; - return true; + return 0; } int32_t taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage) { @@ -544,13 +544,13 @@ int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize) { } } -bool taosGetCardInfo(int64_t *bytes, int64_t *rbytes, int64_t *tbytes) { - *bytes = 0; +int32_t taosGetCardInfo(int64_t *bytes, int64_t *rbytes, int64_t *tbytes) { + if (bytes) *bytes = 0; // FILE *fp = fopen(tsSysNetFile, "r"); TdFilePtr pFile = taosOpenFile(tsSysNetFile, TD_FILE_READ | TD_FILE_STREAM); if (pFile == NULL) { // printf("open file:%s failed", tsSysNetFile); - return false; + return -1; } ssize_t _bytes = 0; @@ -586,37 +586,37 @@ bool taosGetCardInfo(int64_t *bytes, int64_t *rbytes, int64_t *tbytes) { nouse0, &o_rbytes, &rpackts, &nouse1, &nouse2, &nouse3, &nouse4, &nouse5, &nouse6, &o_tbytes, &tpackets); if (rbytes) *rbytes = o_rbytes; if (tbytes) *tbytes = o_tbytes; - *bytes += (o_rbytes + o_tbytes); + if (bytes) *bytes += (o_rbytes + o_tbytes); } if (line != NULL) tfree(line); taosCloseFile(&pFile); - return true; + return 0; } -bool taosGetBandSpeed(float *bandSpeedKb) { +int32_t taosGetBandSpeed(float *bandSpeedKb) { static int64_t lastBytes = 0; static time_t lastTime = 0; int64_t curBytes = 0; time_t curTime = time(NULL); - if (!taosGetCardInfo(&curBytes, NULL, NULL)) { - return false; + if (taosGetCardInfo(&curBytes, NULL, NULL) != 0) { + return -1; } if (lastTime == 0 || lastBytes == 0) { lastTime = curTime; lastBytes = curBytes; *bandSpeedKb = 0; - return true; + return 0; } if (lastTime >= curTime || lastBytes > curBytes) { lastTime = curTime; lastBytes = curBytes; *bandSpeedKb = 0; - return true; + return 0; } double totalBytes = (double)(curBytes - lastBytes) / 1024 * 8; // Kb @@ -628,7 +628,7 @@ bool taosGetBandSpeed(float *bandSpeedKb) { lastTime = curTime; lastBytes = curBytes; - return true; + return 0; } int32_t taosReadProcIO(int64_t *rchars, int64_t *wchars) { -- GitLab