diff --git a/src/os/inc/osSysinfo.h b/src/os/inc/osSysinfo.h index a0c8c0f910257bf864487d0200a8f3d575bf4d25..e2408058f068165506c7e6ffbc6e4ec3dee9a93c 100644 --- a/src/os/inc/osSysinfo.h +++ b/src/os/inc/osSysinfo.h @@ -30,8 +30,8 @@ int32_t taosGetDiskSize(char *dataDir, SysDiskSize *diskSize); int32_t taosGetCpuCores(); void taosGetSystemInfo(); -bool taosReadProcIO(int64_t* rchars, int64_t* wchars); -bool taosGetProcIO(float *readKB, float *writeKB); +bool taosReadProcIO(int64_t* rchars, int64_t* wchars, int64_t* rbytes, int64_t* wbytes); +bool taosGetProcIO(float *rcharKB, float *wcharKB, float *rbyteKB, float* wbyteKB); bool taosGetCardInfo(int64_t *bytes, int64_t *rbytes, int64_t *tbytes); bool taosGetBandSpeed(float *bandSpeedKb); bool taosGetNetworkIO(float *netInKb, float *netOutKb); diff --git a/src/os/src/darwin/dwSysInfo.c b/src/os/src/darwin/dwSysInfo.c index a87a15a3f211768ecce747c7bc6ff236bad2f3ee..f3a64c382e0bf648bbe1d291acfec0992a998197 100644 --- a/src/os/src/darwin/dwSysInfo.c +++ b/src/os/src/darwin/dwSysInfo.c @@ -191,9 +191,11 @@ void taosGetSystemInfo() { taosGetSystemLocale(); } -bool taosReadProcIO(int64_t *rchars, int64_t *wchars) { +bool taosReadProcIO(int64_t *rchars, int64_t *wchars, int64_t *rbytes, int64_t *wbytes) { if (rchars) *rchars = 0; if (wchars) *wchars = 0; + if (rbytes) *rbytes = 0; + if (wbytes) *wbytes = 0; return true; } diff --git a/src/os/src/detail/osSysinfo.c b/src/os/src/detail/osSysinfo.c index 19568fec7d3b4a634f32fc7bf55b4f3e180de05a..93752f34f9ea4b4c55fb682fcc6e2c6c003b31ba 100644 --- a/src/os/src/detail/osSysinfo.c +++ b/src/os/src/detail/osSysinfo.c @@ -465,7 +465,7 @@ bool taosGetNetworkIO(float *netInKb, float *netOutKb) { return true; } -bool taosReadProcIO(int64_t *rchars, int64_t *wchars) { +bool taosReadProcIO(int64_t *rchars, int64_t *wchars, int64_t *rbytes, int64_t *wbytes) { FILE *fp = fopen(tsProcIOFile, "r"); if (fp == NULL) { uError("open file:%s failed", tsProcIOFile); @@ -475,7 +475,7 @@ bool taosReadProcIO(int64_t *rchars, int64_t *wchars) { ssize_t _bytes = 0; size_t len; char * line = NULL; - char tmp[10]; + char tmp[15]; int readIndex = 0; while (!feof(fp)) { @@ -491,16 +491,21 @@ bool taosReadProcIO(int64_t *rchars, int64_t *wchars) { } else if (strstr(line, "wchar:") != NULL) { sscanf(line, "%s %" PRId64, tmp, wchars); readIndex++; - } else { + } else if (strstr(line, "read_bytes:") != NULL){ + sscanf(line, "%s %" PRId64, tmp, rbytes); + readIndex++; + } else if (strstr(line, "write_bytes:") != NULL){ + sscanf(line, "%s %" PRId64, tmp, wbytes); + readIndex++; } - if (readIndex >= 2) break; + if (readIndex >= 4) break; } tfree(line); fclose(fp); - if (readIndex < 2) { + if (readIndex < 4) { uError("read file:%s failed", tsProcIOFile); return false; } @@ -508,30 +513,39 @@ bool taosReadProcIO(int64_t *rchars, int64_t *wchars) { return true; } -bool taosGetProcIO(float *readKB, float *writeKB) { - static int64_t lastReadbyte = -1; - static int64_t lastWritebyte = -1; +bool taosGetProcIO(float *rcharKB, float *wcharKB, float *rbyteKB, float *wbyteKB) { + static int64_t lastRchar = -1, lastRbyte = -1; + static int64_t lastWchar = -1, lastWbyte = -1; - int64_t curReadbyte = 0; - int64_t curWritebyte = 0; + int64_t curRchar = 0, curRbyte = 0; + int64_t curWchar = 0, curWbyte = 0; - if (!taosReadProcIO(&curReadbyte, &curWritebyte)) { + if (!taosReadProcIO(&curRchar, &curWchar, &curRbyte, &curWbyte)) { return false; } - if (lastReadbyte == -1 || lastWritebyte == -1) { - lastReadbyte = curReadbyte; - lastWritebyte = curWritebyte; + if (lastRchar == -1 || lastWchar == -1 || lastRbyte == -1 || lastWbyte == -1) { + lastRchar = curRchar; + lastWchar = curWchar; + lastRbyte = curRbyte; + lastWbyte = curWbyte; return false; } - *readKB = (float)((double)(curReadbyte - lastReadbyte) / 1024); - *writeKB = (float)((double)(curWritebyte - lastWritebyte) / 1024); - if (*readKB < 0) *readKB = 0; - if (*writeKB < 0) *writeKB = 0; + *rcharKB = (float)((double)(curRchar - lastRchar) / 1024); + *wcharKB = (float)((double)(curWchar - lastWchar) / 1024); + if (*rcharKB < 0) *rcharKB = 0; + if (*wcharKB < 0) *wcharKB = 0; + + *rbyteKB = (float)((double)(curRbyte - lastRbyte) / 1024); + *wbyteKB = (float)((double)(curWbyte - lastWbyte) / 1024); + if (*rbyteKB < 0) *rbyteKB = 0; + if (*wbyteKB < 0) *wbyteKB = 0; - lastReadbyte = curReadbyte; - lastWritebyte = curWritebyte; + lastRchar = curRchar; + lastWchar = curWchar; + lastRbyte = curRbyte; + lastWbyte = curWbyte; return true; } @@ -542,13 +556,13 @@ void taosGetSystemInfo() { tsNumOfCores = taosGetCpuCores(); tsTotalMemoryMB = taosGetTotalMemory(); - float tmp1, tmp2; + float tmp1, tmp2, tmp3, tmp4; taosGetSysMemory(&tmp1); taosGetProcMemory(&tmp2); // taosGetDisk(); taosGetBandSpeed(&tmp1); taosGetCpuUsage(&tmp1, &tmp2); - taosGetProcIO(&tmp1, &tmp2); + taosGetProcIO(&tmp1, &tmp2, &tmp3, &tmp4); taosGetSystemTimezone(); taosGetSystemLocale(); diff --git a/src/plugins/http/src/httpMetricsHandle.c b/src/plugins/http/src/httpMetricsHandle.c index 23602af3c7d6b19c9631587c2da3d1149d9ffa75..2031c2a6db2630b8a944cdb582d07e46c1f9313e 100644 --- a/src/plugins/http/src/httpMetricsHandle.c +++ b/src/plugins/http/src/httpMetricsHandle.c @@ -123,9 +123,9 @@ bool metricsProcessRequest(HttpContext* pContext) { } { - int64_t rchars = 0; - int64_t wchars = 0; - bool succeeded = taosReadProcIO(&rchars, &wchars); + int64_t rchars = 0, rbytes = 0; + int64_t wchars = 0, wbytes = 0; + bool succeeded = taosReadProcIO(&rchars, &wchars, &rbytes, &wbytes); if (!succeeded) { httpError("failed to get io info"); } else { diff --git a/src/plugins/monitor/src/monMain.c b/src/plugins/monitor/src/monMain.c index a33e78076109c0d0643237cccba26b4acfc34b10..bf56f6b222a81c5187568a940d0a377754304b3e 100644 --- a/src/plugins/monitor/src/monMain.c +++ b/src/plugins/monitor/src/monMain.c @@ -148,9 +148,17 @@ typedef struct { char sql[SQL_LENGTH + 1]; } SMonConn; +typedef struct { + float io_read; + float io_write; + float io_read_disk; + float io_write_disk; +} SMonStat; + static void *monHttpStatusHashTable; static SMonConn tsMonitor = {0}; +static SMonStat tsMonStat = {0}; static int32_t monQueryReqNum = 0, monSubmitReqNum = 0; static bool monHasMnodeMaster = false; @@ -163,6 +171,7 @@ static void monSaveDisksInfo(); static void monSaveGrantsInfo(); static void monSaveHttpReqInfo(); static void monClearStatisInfo(); +static void monGetSysStats(); static void *monThreadFunc(void *param); static void monBuildMonitorSql(char *sql, int32_t cmd); static void monInitHttpStatusHashTable(); @@ -300,6 +309,7 @@ static void *monThreadFunc(void *param) { if (tsMonitor.state == MON_STATE_INITED) { if (accessTimes % tsMonitorInterval == 0 || accessTimes == 1) { + monGetSysStats(); //monSaveDnodesInfo has to be the first, as it calculates //stats using monSubmitReqNum before any insertion from monitor monSaveDnodesInfo(); @@ -398,6 +408,7 @@ static void monBuildMonitorSql(char *sql, int32_t cmd) { ", disk_engine float, disk_used float, disk_total float" ", net_in float, net_out float" ", io_read float, io_write float" + ", io_read_disk float, io_write_disk float" ", req_http int, req_http_rate float" ", req_select int, req_select_rate float" ", req_insert int, req_insert_success int, req_insert_rate float" @@ -486,6 +497,15 @@ void monCleanupSystem() { monInfo("monitor module is cleaned up"); } +static void monGetSysStats() { + memset(&tsMonStat, 0, sizeof(SMonStat)); + bool suc = taosGetProcIO(&tsMonStat.io_read, &tsMonStat.io_write, + &tsMonStat.io_read_disk, &tsMonStat.io_write_disk); + if (!suc) { + monDebug("failed to get io info"); + } +} + // unit is MB static int32_t monBuildMemorySql(char *sql) { float sysMemoryUsedMB = 0; @@ -541,10 +561,8 @@ static int32_t monBuildReqSql(char *sql) { static int32_t monBuildIoSql(char *sql) { float readKB = 0, writeKB = 0; - bool suc = taosGetProcIO(&readKB, &writeKB); - if (!suc) { - monDebug("failed to get io info"); - } + readKB = tsMonStat.io_read; + writeKB = tsMonStat.io_write; return sprintf(sql, ", %f, %f", readKB, writeKB); }