diff --git a/src/os/src/detail/osSysinfo.c b/src/os/src/detail/osSysinfo.c index 93752f34f9ea4b4c55fb682fcc6e2c6c003b31ba..af8f2dcdaf1568ba5e10656aacb7d0958155dde2 100644 --- a/src/os/src/detail/osSysinfo.c +++ b/src/os/src/detail/osSysinfo.c @@ -516,6 +516,8 @@ bool taosReadProcIO(int64_t *rchars, int64_t *wchars, int64_t *rbytes, int64_t * bool taosGetProcIO(float *rcharKB, float *wcharKB, float *rbyteKB, float *wbyteKB) { static int64_t lastRchar = -1, lastRbyte = -1; static int64_t lastWchar = -1, lastWbyte = -1; + static time_t lastTime = 0; + time_t curTime = time(NULL); int64_t curRchar = 0, curRbyte = 0; int64_t curWchar = 0, curWbyte = 0; @@ -524,7 +526,8 @@ bool taosGetProcIO(float *rcharKB, float *wcharKB, float *rbyteKB, float *wbyteK return false; } - if (lastRchar == -1 || lastWchar == -1 || lastRbyte == -1 || lastWbyte == -1) { + if (lastTime == 0 || lastRchar == -1 || lastWchar == -1 || lastRbyte == -1 || lastWbyte == -1) { + lastTime = curTime; lastRchar = curRchar; lastWchar = curWchar; lastRbyte = curRbyte; @@ -532,13 +535,13 @@ bool taosGetProcIO(float *rcharKB, float *wcharKB, float *rbyteKB, float *wbyteK return false; } - *rcharKB = (float)((double)(curRchar - lastRchar) / 1024); - *wcharKB = (float)((double)(curWchar - lastWchar) / 1024); + *rcharKB = (float)((double)(curRchar - lastRchar) / 1024 / (double)(curTime - lastTime)); + *wcharKB = (float)((double)(curWchar - lastWchar) / 1024 / (double)(curTime - lastTime)); if (*rcharKB < 0) *rcharKB = 0; if (*wcharKB < 0) *wcharKB = 0; - *rbyteKB = (float)((double)(curRbyte - lastRbyte) / 1024); - *wbyteKB = (float)((double)(curWbyte - lastWbyte) / 1024); + *rbyteKB = (float)((double)(curRbyte - lastRbyte) / 1024 / (double)(curTime - lastTime)); + *wbyteKB = (float)((double)(curWbyte - lastWbyte) / 1024 / (double)(curTime - lastTime)); if (*rbyteKB < 0) *rbyteKB = 0; if (*wbyteKB < 0) *wbyteKB = 0; @@ -546,6 +549,7 @@ bool taosGetProcIO(float *rcharKB, float *wcharKB, float *rbyteKB, float *wbyteK lastWchar = curWchar; lastRbyte = curRbyte; lastWbyte = curWbyte; + lastTime = curTime; return true; } diff --git a/src/os/src/windows/wSysinfo.c b/src/os/src/windows/wSysinfo.c index f14f0da0a0de00f4c31dc047d2c0c6d0ee532975..193a83d7d73ee904204fa6ce1a5a1b562c92d17a 100644 --- a/src/os/src/windows/wSysinfo.c +++ b/src/os/src/windows/wSysinfo.c @@ -188,6 +188,8 @@ bool taosReadProcIO(int64_t *rchars, int64_t *wchars, int64_t *rbytes, int64_t * bool taosGetProcIO(float *rcharKB, float *wcharKB, float *rbyteKB, float *wbyteKB) { static int64_t lastRchar = -1, lastRbyte = -1; static int64_t lastWchar = -1, lastWbyte = -1; + static time_t lastTime = 0; + time_t curTime = time(NULL); int64_t curRchar = 0, curRbyte = 0; int64_t curWchar = 0, curWbyte = 0; @@ -196,7 +198,8 @@ bool taosGetProcIO(float *rcharKB, float *wcharKB, float *rbyteKB, float *wbyteK return false; } - if (lastRchar == -1 || lastWchar == -1 || lastRbyte == -1 || lastWbyte == -1) { + if (lastTime == 0 || lastRchar == -1 || lastWchar == -1 || lastRbyte == -1 || lastWbyte == -1) { + lastTime = curTime; lastRchar = curRchar; lastWchar = curWchar; lastRbyte = curRbyte; @@ -204,13 +207,13 @@ bool taosGetProcIO(float *rcharKB, float *wcharKB, float *rbyteKB, float *wbyteK return false; } - *rcharKB = (float)((double)(curRchar - lastRchar) / 1024); - *wcharKB = (float)((double)(curWchar - lastWchar) / 1024); + *rcharKB = (float)((double)(curRchar - lastRchar) / 1024 / (double)(curTime - lastTime)); + *wcharKB = (float)((double)(curWchar - lastWchar) / 1024 / (double)(curTime - lastTime)); if (*rcharKB < 0) *rcharKB = 0; if (*wcharKB < 0) *wcharKB = 0; - *rbyteKB = (float)((double)(curRbyte - lastRbyte) / 1024); - *wbyteKB = (float)((double)(curWbyte - lastWbyte) / 1024); + *rbyteKB = (float)((double)(curRbyte - lastRbyte) / 1024 / (double)(curTime - lastTime)); + *wbyteKB = (float)((double)(curWbyte - lastWbyte) / 1024 / (double)(curTime - lastTime)); if (*rbyteKB < 0) *rbyteKB = 0; if (*wbyteKB < 0) *wbyteKB = 0; @@ -218,6 +221,7 @@ bool taosGetProcIO(float *rcharKB, float *wcharKB, float *rbyteKB, float *wbyteK lastWchar = curWchar; lastRbyte = curRbyte; lastWbyte = curWbyte; + lastTime = curTime; return true; } diff --git a/src/plugins/monitor/src/monMain.c b/src/plugins/monitor/src/monMain.c index bc3c7485eaa37a310ab3391eddd2e2796d6ec0e3..fc06b920939b1edb0ebfb1ed16da9dcb60edfd3a 100644 --- a/src/plugins/monitor/src/monMain.c +++ b/src/plugins/monitor/src/monMain.c @@ -860,7 +860,7 @@ static int32_t monBuildDnodeUptimeSql(char *sql) { for (int i = 0; i < num_fields; ++i) { if (strcmp(fields[i].name, "end_point") == 0) { int32_t charLen = monGetRowElemCharLen(fields[i], (char *)row[i]); - if (strncmp((char *)row[i], tsLocalEp, charLen)) { + if (strncmp((char *)row[i], tsLocalEp, charLen) == 0) { is_self_ep = true; } } @@ -887,8 +887,8 @@ static int32_t monBuildDnodeIoSql(char *sql) { rbyteKB = tsMonStat.io_read_disk; wbyteKB = tsMonStat.io_write_disk; - return snprintf(sql, SQL_LENGTH, ", %f, %f, %f, %f", (rcharKB / 1024) / tsMonitorInterval, (wcharKB / 1024) / tsMonitorInterval, - (rbyteKB / 1024) / tsMonitorInterval, (wbyteKB / 1024) / tsMonitorInterval); + return snprintf(sql, SQL_LENGTH, ", %f, %f, %f, %f", rcharKB / 1024, wcharKB / 1024, + rbyteKB / 1024, wbyteKB / 1024); } static int32_t monBuildNetworkIOSql(char *sql) {