From 5e2417a1b8a443c2ec06f53e1a4d40c5d8debba3 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Thu, 18 Nov 2021 16:03:24 +0800 Subject: [PATCH] fix dnodes uptime and interval --- src/os/src/detail/osSysinfo.c | 14 +++++++++----- src/os/src/windows/wSysinfo.c | 14 +++++++++----- src/plugins/monitor/src/monMain.c | 6 +++--- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/os/src/detail/osSysinfo.c b/src/os/src/detail/osSysinfo.c index 93752f34f9..af8f2dcdaf 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 f14f0da0a0..193a83d7d7 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 bc3c7485ea..fc06b92093 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) { -- GitLab