diff --git a/src/common/inc/tglobal.h b/src/common/inc/tglobal.h index bd201d980017522d0e32f6124290305d5b136f8d..317d48ea5987935c5d53af6ad578834071643f26 100644 --- a/src/common/inc/tglobal.h +++ b/src/common/inc/tglobal.h @@ -148,6 +148,7 @@ extern char tsMqttTopic[]; // monitor extern int8_t tsEnableMonitorModule; +extern int8_t tsMonitorReplica; extern char tsMonitorDbName[]; extern char tsInternalPass[]; extern int32_t tsMonitorInterval; diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index f13a35f0b9ae287f04cccf1785fce77f8d5c0678..62baaadbac2596bc66bf5955262a3d5ff35fcfc1 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -193,6 +193,7 @@ char tsMqttTopic[TSDB_MQTT_TOPIC_LEN] = "/test"; // # // monitor int8_t tsEnableMonitorModule = 1; +int8_t tsMonitorReplica = 1; char tsMonitorDbName[TSDB_DB_NAME_LEN] = "log"; char tsInternalPass[] = "secretkey"; int32_t tsMonitorInterval = 30; // seconds @@ -669,6 +670,16 @@ static void doInitGlobalConfig(void) { cfg.unitType = TAOS_CFG_UTYPE_SECOND; taosInitConfigOption(cfg); + cfg.option = "monitorReplica"; + cfg.ptr = &tsMonitorReplica; + cfg.valType = TAOS_CFG_VTYPE_INT8; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 1; + cfg.maxValue = 3; + cfg.ptrLength = 1; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + cfg.option = "offlineThreshold"; cfg.ptr = &tsOfflineThreshold; cfg.valType = TAOS_CFG_VTYPE_INT32; diff --git a/src/dnode/inc/dnodeInt.h b/src/dnode/inc/dnodeInt.h index 1327cd4433fd2e2157becaaf5cb52e2ca0ffe6ef..7abff373834a2f2ddf39dbffb1ebcaadc6991dc9 100644 --- a/src/dnode/inc/dnodeInt.h +++ b/src/dnode/inc/dnodeInt.h @@ -29,8 +29,8 @@ extern "C" { extern int32_t dDebugFlag; -#define dFatal(...) { if (dDebugFlag & DEBUG_FATAL) { taosPrintLog("DND FATAL ", 255, __VA_ARGS__); }} -#define dError(...) { if (dDebugFlag & DEBUG_ERROR) { taosPrintLog("DND ERROR ", 255, __VA_ARGS__); }} +#define dFatal(...) { if (dDebugFlag & DEBUG_FATAL) { taosPrintLog("DND FATAL ", 255, __VA_ARGS__); dnodeIncDnodeError(); }} +#define dError(...) { if (dDebugFlag & DEBUG_ERROR) { taosPrintLog("DND ERROR ", 255, __VA_ARGS__); dnodeIncDnodeError(); }} #define dWarn(...) { if (dDebugFlag & DEBUG_WARN) { taosPrintLog("DND WARN ", 255, __VA_ARGS__); }} #define dInfo(...) { if (dDebugFlag & DEBUG_INFO) { taosPrintLog("DND ", 255, __VA_ARGS__); }} #define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("DND ", dDebugFlag, __VA_ARGS__); }} diff --git a/src/dnode/src/dnodeMain.c b/src/dnode/src/dnodeMain.c index 0dc10385cfbf648ce90f3dabaf87c9a2ea189b6f..69c6203ab355e93272113b0cdfbab3e066be8148 100644 --- a/src/dnode/src/dnodeMain.c +++ b/src/dnode/src/dnodeMain.c @@ -54,6 +54,7 @@ void moduleStop() {} void *tsDnodeTmr = NULL; static SRunStatus tsRunStatus = TSDB_RUN_STATUS_STOPPED; +static int64_t tsDnodeErrors = 0; static int32_t dnodeInitStorage(); static void dnodeCleanupStorage(); @@ -225,6 +226,14 @@ static void dnodeSetRunStatus(SRunStatus status) { tsRunStatus = status; } +int64_t dnodeGetDnodeError() { + return tsDnodeErrors; +} + +void dnodeIncDnodeError() { + atomic_add_fetch_64(&tsDnodeErrors, 1); +} + static void dnodeCheckDataDirOpenned(char *dir) { char filepath[256] = {0}; sprintf(filepath, "%s/.running", dir); diff --git a/src/dnode/src/dnodeShell.c b/src/dnode/src/dnodeShell.c index 98bbbf8f73b26535030c5096f128a7f84c2b9f61..f62e0c0df41f2fe399d0f4c1c8e661fcd0ef91b9 100644 --- a/src/dnode/src/dnodeShell.c +++ b/src/dnode/src/dnodeShell.c @@ -28,8 +28,8 @@ static void (*dnodeProcessShellMsgFp[TSDB_MSG_TYPE_MAX])(SRpcMsg *); static void dnodeProcessMsgFromShell(SRpcMsg *pMsg, SRpcEpSet *); static int dnodeRetrieveUserAuthInfo(char *user, char *spi, char *encrypt, char *secret, char *ckey); static void * tsShellRpc = NULL; -static int32_t tsQueryReqNum = 0; -static int32_t tsSubmitReqNum = 0; +static int64_t tsQueryReqNum = 0; +static int64_t tsSubmitReqNum = 0; int32_t dnodeInitShell() { dnodeProcessShellMsgFp[TSDB_MSG_TYPE_SUBMIT] = dnodeDispatchToVWriteQueue; @@ -136,9 +136,9 @@ static void dnodeProcessMsgFromShell(SRpcMsg *pMsg, SRpcEpSet *pEpSet) { } if (pMsg->msgType == TSDB_MSG_TYPE_QUERY) { - atomic_fetch_add_32(&tsQueryReqNum, 1); + atomic_fetch_add_64(&tsQueryReqNum, 1); } else if (pMsg->msgType == TSDB_MSG_TYPE_SUBMIT) { - atomic_fetch_add_32(&tsSubmitReqNum, 1); + atomic_fetch_add_64(&tsSubmitReqNum, 1); } else {} if ( dnodeProcessShellMsgFp[pMsg->msgType] ) { @@ -237,15 +237,31 @@ void *dnodeSendCfgTableToRecv(int32_t vgId, int32_t tid) { } } -SStatisInfo dnodeGetStatisInfo() { - SStatisInfo info = {0}; +SDnodeStatisInfo dnodeGetStatisInfo() { + SDnodeStatisInfo info = {0}; if (dnodeGetRunStatus() == TSDB_RUN_STATUS_RUNING) { #ifdef HTTP_EMBEDDED info.httpReqNum = httpGetReqCount(); #endif - info.queryReqNum = atomic_exchange_32(&tsQueryReqNum, 0); - info.submitReqNum = atomic_exchange_32(&tsSubmitReqNum, 0); + info.queryReqNum = atomic_exchange_64(&tsQueryReqNum, 0); + info.submitReqNum = atomic_exchange_64(&tsSubmitReqNum, 0); } return info; } + +int32_t dnodeGetHttpStatusInfo(int32_t index) { + int32_t httpStatus = 0; +#ifdef HTTP_EMBEDDED + httpStatus = httpGetStatusCodeCount(index); +#endif + return httpStatus; +} + +void dnodeClearHttpStatusInfo() { +#ifdef HTTP_EMBEDDED + for (int i = 0; i < MAX_HTTP_STATUS_CODE_NUM; ++i) { + httpClearStatusCodeCount(i); + } +#endif +} diff --git a/src/inc/dnode.h b/src/inc/dnode.h index 5ecaf19f61a022bae849c2f946acb0ee693aeb59..117b8a5657046abb6412144b352fca79b9d590da 100644 --- a/src/inc/dnode.h +++ b/src/inc/dnode.h @@ -23,13 +23,16 @@ extern "C" { #include "trpc.h" #include "taosmsg.h" +#define MAX_HTTP_STATUS_CODE_NUM 63 typedef struct { - int32_t queryReqNum; - int32_t submitReqNum; - int32_t httpReqNum; -} SStatisInfo; + int64_t queryReqNum; + int64_t submitReqNum; + int64_t httpReqNum; +} SDnodeStatisInfo; -SStatisInfo dnodeGetStatisInfo(); +SDnodeStatisInfo dnodeGetStatisInfo(); +int32_t dnodeGetHttpStatusInfo(int32_t index); +void dnodeClearHttpStatusInfo(); bool dnodeIsFirstDeploy(); bool dnodeIsMasterEp(char *ep); @@ -37,6 +40,8 @@ void dnodeGetEpSetForPeer(SRpcEpSet *epSet); void dnodeGetEpSetForShell(SRpcEpSet *epSet); int32_t dnodeGetDnodeId(); void dnodeGetClusterId(char *clusterId); +int64_t dnodeGetDnodeError(); +void dnodeIncDnodeError(); void dnodeUpdateEp(int32_t dnodeId, char *ep, char *fqdn, uint16_t *port); bool dnodeCheckEpChanged(int32_t dnodeId, char *epstr); diff --git a/src/inc/http.h b/src/inc/http.h index 0d4c386cbf1e784834019c5d75847ab20b7ce8e9..7333042641a8f7bda1574e77e373c7e9a258751d 100644 --- a/src/inc/http.h +++ b/src/inc/http.h @@ -22,7 +22,9 @@ extern "C" { #include -int32_t httpGetReqCount(); +int64_t httpGetReqCount(); +int32_t httpGetStatusCodeCount(int index); +int32_t httpClearStatusCodeCount(int index); int32_t httpInitSystem(); int32_t httpStartSystem(); void httpStopSystem(); diff --git a/src/inc/monitor.h b/src/inc/monitor.h index d2e5e06487dbdf311cef6da125d7ba3050b53a4d..6033f91ee72acb09f23f07fc32e6a40cf0136d76 100644 --- a/src/inc/monitor.h +++ b/src/inc/monitor.h @@ -22,6 +22,17 @@ extern "C" { #include +#define monSaveLogs(level, ...) { \ + monSaveLog(level, __VA_ARGS__); \ + monSaveDnodeLog(level, __VA_ARGS__); \ +} + +typedef struct { + const char * name; + int32_t code; + int32_t index; +} SMonHttpStatus; + typedef struct { char * acctId; int64_t currentPointsPerSecond; @@ -53,9 +64,16 @@ void monStopSystem(); void monCleanupSystem(); void monSaveAcctLog(SAcctMonitorObj *pMonObj); void monSaveLog(int32_t level, const char *const format, ...); +void monSaveDnodeLog(int32_t level, const char *const format, ...); void monExecuteSQL(char *sql); typedef void (*MonExecuteSQLCbFP)(void *param, TAOS_RES *, int code); void monExecuteSQLWithResultCallback(char *sql, MonExecuteSQLCbFP callback, void* param); +void monIncQueryReqCnt(); +void monIncSubmitReqCnt(); +int32_t monFetchQueryReqCnt(); +int32_t monFetchSubmitReqCnt(); +SMonHttpStatus *monGetHttpStatusHashTableEntry(int32_t code); + #ifdef __cplusplus } #endif diff --git a/src/inc/vnode.h b/src/inc/vnode.h index b3291645c00be17283f7d078acb2d4c9a2629ece..29766e39842e9b53243e4d367116c8bc9ed35f7a 100644 --- a/src/inc/vnode.h +++ b/src/inc/vnode.h @@ -22,6 +22,12 @@ extern "C" { #include "trpc.h" #include "twal.h" +typedef struct { + int64_t submitReqSucNum; + int64_t submitRowNum; + int64_t submitRowSucNum; +} SVnodeStatisInfo; + typedef struct { int32_t len; void * rsp; @@ -62,7 +68,7 @@ int32_t vnodeOpen(int32_t vgId); int32_t vnodeAlter(void *pVnode, SCreateVnodeMsg *pVnodeCfg); int32_t vnodeSync(int32_t vgId); int32_t vnodeClose(int32_t vgId); -int32_t vnodeCompact(int32_t vgId); +int32_t vnodeCompact(int32_t vgId); // vnodeMgmt int32_t vnodeInitMgmt(); @@ -80,6 +86,8 @@ int32_t vnodeWriteToWQueue(void *pVnode, void *pHead, int32_t qtype, void *pRpcM void vnodeFreeFromWQueue(void *pVnode, SVWriteMsg *pWrite); int32_t vnodeProcessWrite(void *pVnode, void *pHead, int32_t qtype, void *pRspRet); +SVnodeStatisInfo vnodeGetStatisInfo(); + // vnodeSync void vnodeConfirmForward(void *pVnode, uint64_t version, int32_t code, bool force); diff --git a/src/mnode/inc/mnodeInt.h b/src/mnode/inc/mnodeInt.h index 7a791d76e6796cfed22657f1bc7ffdb26890ea40..aefdf23bdadaed47e56435ca8e8c0d049bec3ea4 100644 --- a/src/mnode/inc/mnodeInt.h +++ b/src/mnode/inc/mnodeInt.h @@ -41,9 +41,9 @@ extern int32_t sdbDebugFlag; #define sdbDebug(...) { if (sdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("SDB ", sdbDebugFlag, __VA_ARGS__); }} #define sdbTrace(...) { if (sdbDebugFlag & DEBUG_TRACE) { taosPrintLog("SDB ", sdbDebugFlag, __VA_ARGS__); }} -#define mLError(...) { monSaveLog(2, __VA_ARGS__); mError(__VA_ARGS__) } -#define mLWarn(...) { monSaveLog(1, __VA_ARGS__); mWarn(__VA_ARGS__) } -#define mLInfo(...) { monSaveLog(0, __VA_ARGS__); mInfo(__VA_ARGS__) } +#define mLError(...) { monSaveLogs(2, __VA_ARGS__); mError(__VA_ARGS__) } +#define mLWarn(...) { monSaveLogs(1, __VA_ARGS__); mWarn(__VA_ARGS__) } +#define mLInfo(...) { monSaveLogs(0, __VA_ARGS__); mInfo(__VA_ARGS__) } #ifdef __cplusplus } diff --git a/src/mnode/src/mnodeDnode.c b/src/mnode/src/mnodeDnode.c index 7dd199cca4248e5467017e1b6247f3b534c45711..168995916553dc8b1d02f9cd05563cfb4c5319de 100644 --- a/src/mnode/src/mnodeDnode.c +++ b/src/mnode/src/mnodeDnode.c @@ -1177,8 +1177,8 @@ static int32_t mnodeGetVnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pC int32_t cols = 0; SUserObj *pUser = mnodeGetUserFromConn(pConn); if (pUser == NULL) return 0; - - if (strcmp(pUser->user, TSDB_DEFAULT_USER) != 0) { + + if (strcmp(pUser->pAcct->user, TSDB_DEFAULT_USER) != 0 ) { mnodeDecUserRef(pUser); return TSDB_CODE_MND_NO_RIGHTS; } @@ -1256,10 +1256,10 @@ static int32_t mnodeRetrieveVnodes(SShowObj *pShow, char *data, int32_t rows, vo STR_TO_VARSTR(pWrite, syncRole[pVgid->role]); cols++; numOfRows++; - } } if (numOfRows >= rows) { + mnodeDecVgroupRef(pVgroup); break; } diff --git a/src/mnode/src/mnodeProfile.c b/src/mnode/src/mnodeProfile.c index 15438fc234bb60089e9d0f52fe92eb5bf8b3eeae..70532d2216a9ad4ecb8e3ceca94367a535796a9e 100644 --- a/src/mnode/src/mnodeProfile.c +++ b/src/mnode/src/mnodeProfile.c @@ -166,7 +166,7 @@ static void mnodeCancelGetNextConn(void *pIter) { static int32_t mnodeGetConnsMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { SUserObj *pUser = mnodeGetUserFromConn(pConn); if (pUser == NULL) return 0; - if (strcmp(pUser->user, TSDB_DEFAULT_USER) != 0) return TSDB_CODE_MND_NO_RIGHTS; + if (strcmp(pUser->pAcct->user, TSDB_DEFAULT_USER) != 0) return TSDB_CODE_MND_NO_RIGHTS; int32_t cols = 0; SSchema *pSchema = pMeta->schema; @@ -322,7 +322,7 @@ int32_t mnodeSaveQueryStreamList(SConnObj *pConn, SHeartBeatMsg *pHBMsg) { static int32_t mnodeGetQueryMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { SUserObj *pUser = mnodeGetUserFromConn(pConn); if (pUser == NULL) return 0; - if (strcmp(pUser->user, TSDB_DEFAULT_USER) != 0) return TSDB_CODE_MND_NO_RIGHTS; + if (strcmp(pUser->pAcct->user, TSDB_DEFAULT_USER) != 0) return TSDB_CODE_MND_NO_RIGHTS; int32_t cols = 0; SSchema *pSchema = pMeta->schema; diff --git a/src/os/inc/osSysinfo.h b/src/os/inc/osSysinfo.h index 0320ab0f7fe5f72e70fd6d12d8d2b0a27dec3754..e2408058f068165506c7e6ffbc6e4ec3dee9a93c 100644 --- a/src/os/inc/osSysinfo.h +++ b/src/os/inc/osSysinfo.h @@ -30,10 +30,11 @@ 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); void taosGetDisk(); bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage) ; bool taosGetProcMemory(float *memoryUsedMB) ; diff --git a/src/os/src/darwin/dwSysInfo.c b/src/os/src/darwin/dwSysInfo.c index a87a15a3f211768ecce747c7bc6ff236bad2f3ee..8cfba775688b221a85667df86dea0c46f54e02cc 100644 --- a/src/os/src/darwin/dwSysInfo.c +++ b/src/os/src/darwin/dwSysInfo.c @@ -191,15 +191,19 @@ 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; } -bool taosGetProcIO(float *readKB, float *writeKB) { - *readKB = 0; - *writeKB = 0; +bool taosGetProcIO(float *rcharKB, float *wcharKB, float *rbyteKB, float *wbyteKB) { + *rcharKB = 0; + *wcharKB = 0; + *rbyteKB = 0; + *wbyteKB = 0; return true; } @@ -215,6 +219,12 @@ bool taosGetBandSpeed(float *bandSpeedKb) { return true; } +bool taosGetNetworkIO(float *netInKb, float *netOutKb) { + *netInKb = 0; + *netOutKb = 0; + return true; +} + bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage) { *sysCpuUsage = 0; *procCpuUsage = 0; diff --git a/src/os/src/detail/osSysinfo.c b/src/os/src/detail/osSysinfo.c index 64d33be40ed09b2783b4c7e08b6c20618a43cf8a..af8f2dcdaf1568ba5e10656aacb7d0958155dde2 100644 --- a/src/os/src/detail/osSysinfo.c +++ b/src/os/src/detail/osSysinfo.c @@ -335,7 +335,9 @@ int32_t taosGetDiskSize(char *dataDir, SysDiskSize *diskSize) { } bool taosGetCardInfo(int64_t *bytes, int64_t *rbytes, int64_t *tbytes) { - *bytes = 0; + if (bytes) *bytes = 0; + if (rbytes) *rbytes = 0; + if (tbytes) *tbytes = 0; FILE *fp = fopen(tsSysNetFile, "r"); if (fp == NULL) { uError("open file:%s failed", tsSysNetFile); @@ -350,7 +352,7 @@ bool taosGetCardInfo(int64_t *bytes, int64_t *rbytes, int64_t *tbytes) { memset(line, 0, len); int64_t o_rbytes = 0; - int64_t rpackts = 0; + int64_t rpackets = 0; int64_t o_tbytes = 0; int64_t tpackets = 0; int64_t nouse1 = 0; @@ -376,10 +378,10 @@ bool taosGetCardInfo(int64_t *bytes, int64_t *rbytes, int64_t *tbytes) { sscanf(line, "%s %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64, - nouse0, &o_rbytes, &rpackts, &nouse1, &nouse2, &nouse3, &nouse4, &nouse5, &nouse6, &o_tbytes, &tpackets); + nouse0, &o_rbytes, &rpackets, &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); } tfree(line); @@ -424,7 +426,46 @@ bool taosGetBandSpeed(float *bandSpeedKb) { return true; } -bool taosReadProcIO(int64_t *rchars, int64_t *wchars) { +bool taosGetNetworkIO(float *netInKb, float *netOutKb) { + static int64_t lastBytesIn = 0, lastBytesOut = 0; + static time_t lastTimeIO = 0; + int64_t curBytesIn = 0, curBytesOut = 0; + time_t curTime = time(NULL); + + if (!taosGetCardInfo(NULL, &curBytesIn, &curBytesOut)) { + return false; + } + + if (lastTimeIO == 0 || lastBytesIn == 0 || lastBytesOut == 0) { + lastTimeIO = curTime; + lastBytesIn = curBytesIn; lastBytesOut = curBytesOut; + *netInKb = 0; + *netOutKb = 0; + return true; + } + + if (lastTimeIO >= curTime || lastBytesIn > curBytesIn || lastBytesOut > curBytesOut) { + lastTimeIO = curTime; + lastBytesIn = curBytesIn; lastBytesOut = curBytesOut; + *netInKb = 0; + *netOutKb = 0; + return true; + } + + double totalBytesIn = (double)(curBytesIn - lastBytesIn) / 1024 * 8; // Kb + *netInKb = (float)(totalBytesIn / (double)(curTime - lastTimeIO)); + + double totalBytesOut = (double)(curBytesOut - lastBytesOut) / 1024 * 8; // Kb + *netOutKb = (float)(totalBytesOut / (double)(curTime - lastTimeIO)); + + lastTimeIO = curTime; + lastBytesIn = curBytesIn; + lastBytesOut = curBytesOut; + + return true; +} + +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); @@ -434,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)) { @@ -450,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; } @@ -467,30 +513,43 @@ 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; + static time_t lastTime = 0; + time_t curTime = time(NULL); - 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 (lastTime == 0 || lastRchar == -1 || lastWchar == -1 || lastRbyte == -1 || lastWbyte == -1) { + lastTime = curTime; + 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 / (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 / (double)(curTime - lastTime)); + *wbyteKB = (float)((double)(curWbyte - lastWbyte) / 1024 / (double)(curTime - lastTime)); + if (*rbyteKB < 0) *rbyteKB = 0; + if (*wbyteKB < 0) *wbyteKB = 0; - lastReadbyte = curReadbyte; - lastWritebyte = curWritebyte; + lastRchar = curRchar; + lastWchar = curWchar; + lastRbyte = curRbyte; + lastWbyte = curWbyte; + lastTime = curTime; return true; } @@ -501,13 +560,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/os/src/windows/wSysinfo.c b/src/os/src/windows/wSysinfo.c index 831a6bdaf09c32e0e1a35bb240200de437b36ae4..193a83d7d73ee904204fa6ce1a5a1b562c92d17a 100644 --- a/src/os/src/windows/wSysinfo.c +++ b/src/os/src/windows/wSysinfo.c @@ -169,40 +169,59 @@ bool taosGetBandSpeed(float *bandSpeedKb) { return true; } -bool taosReadProcIO(int64_t *readbyte, int64_t *writebyte) { +bool taosGetNetworkIO(float *netInKb, float *netOutKb) { + *netInKb = 0; + *netOutKb = 0; + return true; +} + +bool taosReadProcIO(int64_t *rchars, int64_t *wchars, int64_t *rbytes, int64_t *wbytes) { IO_COUNTERS io_counter; if (GetProcessIoCounters(GetCurrentProcess(), &io_counter)) { - if (readbyte) *readbyte = io_counter.ReadTransferCount; - if (writebyte) *writebyte = io_counter.WriteTransferCount; + if (rchars) *rchars = io_counter.ReadTransferCount; + if (wchars) *wchars = io_counter.WriteTransferCount; return true; } return false; } -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; + static time_t lastTime = 0; + time_t curTime = time(NULL); - 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 (lastTime == 0 || lastRchar == -1 || lastWchar == -1 || lastRbyte == -1 || lastWbyte == -1) { + lastTime = curTime; + 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 / (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 / (double)(curTime - lastTime)); + *wbyteKB = (float)((double)(curWbyte - lastWbyte) / 1024 / (double)(curTime - lastTime)); + if (*rbyteKB < 0) *rbyteKB = 0; + if (*wbyteKB < 0) *wbyteKB = 0; - lastReadbyte = curReadbyte; - lastWritebyte = curWritebyte; + lastRchar = curRchar; + lastWchar = curWchar; + lastRbyte = curRbyte; + lastWbyte = curWbyte; + lastTime = curTime; return true; } @@ -211,11 +230,11 @@ void taosGetSystemInfo() { tsNumOfCores = taosGetCpuCores(); tsTotalMemoryMB = taosGetTotalMemory(); - float tmp1, tmp2; + float tmp1, tmp2, tmp3, tmp4; // taosGetDisk(); taosGetBandSpeed(&tmp1); taosGetCpuUsage(&tmp1, &tmp2); - taosGetProcIO(&tmp1, &tmp2); + taosGetProcIO(&tmp1, &tmp2, &tmp3, &tmp4); taosGetSystemTimezone(); taosGetSystemLocale(); diff --git a/src/plugins/http/inc/httpInt.h b/src/plugins/http/inc/httpInt.h index af0f4c579557d1bd919847ef858af8dc1616bb6f..de595907659ffc84c42afb7802b1a7902b126ea1 100644 --- a/src/plugins/http/inc/httpInt.h +++ b/src/plugins/http/inc/httpInt.h @@ -42,6 +42,7 @@ #define HTTP_WRITE_WAIT_TIME_MS 5 #define HTTP_PASSWORD_LEN TSDB_UNI_LEN #define HTTP_SESSION_ID_LEN (TSDB_USER_LEN + HTTP_PASSWORD_LEN) +#define HTTP_STATUS_CODE_NUM 63 typedef enum HttpReqType { HTTP_REQTYPE_OTHERS = 0, @@ -187,8 +188,9 @@ typedef struct HttpServer { SOCKET fd; int32_t numOfThreads; int32_t methodScannerLen; - int32_t requestNum; + int64_t requestNum; int32_t status; + int32_t statusCodeErrs[HTTP_STATUS_CODE_NUM]; pthread_t thread; HttpThread * pThreads; void * contextCache; diff --git a/src/plugins/http/src/httpMetricsHandle.c b/src/plugins/http/src/httpMetricsHandle.c index dbabd48774aa077b1b4f842b4bc47dfd5de67ce4..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 { @@ -164,7 +164,7 @@ bool metricsProcessRequest(HttpContext* pContext) { } { - SStatisInfo info = dnodeGetStatisInfo(); + SDnodeStatisInfo info = dnodeGetStatisInfo(); { char* keyReqHttp = "req_http"; char* keyReqSelect = "req_select"; @@ -181,4 +181,4 @@ bool metricsProcessRequest(HttpContext* pContext) { pContext->reqType = HTTP_REQTYPE_OTHERS; httpFreeJsonBuf(pContext); return false; -} \ No newline at end of file +} diff --git a/src/plugins/http/src/httpResp.c b/src/plugins/http/src/httpResp.c index 824ce746704b477ee482d82fc617ce37af307a59..a2452a16b94fea060a370c86518bb36c1da45070 100644 --- a/src/plugins/http/src/httpResp.c +++ b/src/plugins/http/src/httpResp.c @@ -21,6 +21,7 @@ #include "httpResp.h" #include "httpJson.h" #include "httpContext.h" +#include "monitor.h" const char *httpKeepAliveStr[] = {"", "Connection: Keep-Alive\r\n", "Connection: Close\r\n"}; @@ -153,6 +154,10 @@ void httpSendErrorResp(HttpContext *pContext, int32_t errNo) { httpCode = pContext->parser->httpCode; } + HttpServer *pServer = &tsHttpServer; + SMonHttpStatus *httpStatus = monGetHttpStatusHashTableEntry(httpCode); + pServer->statusCodeErrs[httpStatus->index] += 1; + pContext->error = true; char *httpCodeStr = httpGetStatusDesc(httpCode); diff --git a/src/plugins/http/src/httpServer.c b/src/plugins/http/src/httpServer.c index 13a0835c3960333c6d12aa443025de5fb95d565e..68d160c3cfd5fd06df36fce98badea036d77907e 100644 --- a/src/plugins/http/src/httpServer.c +++ b/src/plugins/http/src/httpServer.c @@ -190,7 +190,7 @@ static void httpProcessHttpData(void *param) { } else { if (httpReadData(pContext)) { (*(pThread->processData))(pContext); - atomic_fetch_add_32(&pServer->requestNum, 1); + atomic_fetch_add_64(&pServer->requestNum, 1); } } } diff --git a/src/plugins/http/src/httpSystem.c b/src/plugins/http/src/httpSystem.c index 085863f4e410ec7f80e531db6045594fbed37201..1e388541acf825e4852443bd385c08832b03147a 100644 --- a/src/plugins/http/src/httpSystem.c +++ b/src/plugins/http/src/httpSystem.c @@ -120,4 +120,10 @@ void httpCleanUpSystem() { tsHttpServer.status = HTTP_SERVER_CLOSED; } -int32_t httpGetReqCount() { return atomic_exchange_32(&tsHttpServer.requestNum, 0); } +int64_t httpGetReqCount() { return atomic_exchange_64(&tsHttpServer.requestNum, 0); } +int32_t httpGetStatusCodeCount(int index) { + return atomic_load_32(&tsHttpServer.statusCodeErrs[index]); +} +int32_t httpClearStatusCodeCount(int index) { + return atomic_exchange_32(&tsHttpServer.statusCodeErrs[index], 0); +} diff --git a/src/plugins/monitor/src/monMain.c b/src/plugins/monitor/src/monMain.c index fea793fa860fd17ff30bcecae1436180bc6b34bf..fc06b920939b1edb0ebfb1ed16da9dcb60edfd3a 100644 --- a/src/plugins/monitor/src/monMain.c +++ b/src/plugins/monitor/src/monMain.c @@ -17,12 +17,14 @@ #include "os.h" #include "taosdef.h" #include "taoserror.h" +#include "tfs.h" #include "tlog.h" #include "ttimer.h" #include "tutil.h" #include "tscUtil.h" #include "tsclient.h" #include "dnode.h" +#include "vnode.h" #include "monitor.h" #include "taoserror.h" @@ -33,10 +35,79 @@ #define monDebug(...) { if (monDebugFlag & DEBUG_DEBUG) { taosPrintLog("MON ", monDebugFlag, __VA_ARGS__); }} #define monTrace(...) { if (monDebugFlag & DEBUG_TRACE) { taosPrintLog("MON ", monDebugFlag, __VA_ARGS__); }} -#define SQL_LENGTH 1030 -#define LOG_LEN_STR 512 -#define IP_LEN_STR TSDB_EP_LEN -#define CHECK_INTERVAL 1000 +#define SQL_LENGTH 4096 +#define LOG_LEN_STR 512 +#define IP_LEN_STR TSDB_EP_LEN +#define VGROUP_STATUS_LEN 512 +#define DNODE_INFO_LEN 128 +#define QUERY_ID_LEN 24 +#define CHECK_INTERVAL 1000 + +static SMonHttpStatus monHttpStatusTable[] = { + {"HTTP_CODE_CONTINUE", 100}, + {"HTTP_CODE_SWITCHING_PROTOCOL", 101}, + {"HTTP_CODE_PROCESSING", 102}, + {"HTTP_CODE_EARLY_HINTS", 103}, + {"HTTP_CODE_OK", 200}, + {"HTTP_CODE_CREATED", 201}, + {"HTTP_CODE_ACCEPTED", 202}, + {"HTTP_CODE_NON_AUTHORITATIVE_INFO", 203}, + {"HTTP_CODE_NO_CONTENT", 204}, + {"HTTP_CODE_RESET_CONTENT", 205}, + {"HTTP_CODE_PARTIAL_CONTENT", 206}, + {"HTTP_CODE_MULTI_STATUS", 207}, + {"HTTP_CODE_ALREADY_REPORTED", 208}, + {"HTTP_CODE_IM_USED", 226}, + {"HTTP_CODE_MULTIPLE_CHOICE", 300}, + {"HTTP_CODE_MOVED_PERMANENTLY", 301}, + {"HTTP_CODE_FOUND", 302}, + {"HTTP_CODE_SEE_OTHER", 303}, + {"HTTP_CODE_NOT_MODIFIED", 304}, + {"HTTP_CODE_USE_PROXY", 305}, + {"HTTP_CODE_UNUSED", 306}, + {"HTTP_CODE_TEMPORARY_REDIRECT", 307}, + {"HTTP_CODE_PERMANENT_REDIRECT", 308}, + {"HTTP_CODE_BAD_REQUEST", 400}, + {"HTTP_CODE_UNAUTHORIZED", 401}, + {"HTTP_CODE_PAYMENT_REQUIRED", 402}, + {"HTTP_CODE_FORBIDDEN", 403}, + {"HTTP_CODE_NOT_FOUND", 404}, + {"HTTP_CODE_METHOD_NOT_ALLOWED", 405}, + {"HTTP_CODE_NOT_ACCEPTABLE", 406}, + {"HTTP_CODE_PROXY_AUTH_REQUIRED", 407}, + {"HTTP_CODE_REQUEST_TIMEOUT", 408}, + {"HTTP_CODE_CONFLICT", 409}, + {"HTTP_CODE_GONE", 410}, + {"HTTP_CODE_LENGTH_REQUIRED", 411}, + {"HTTP_CODE_PRECONDITION_FAILED", 412}, + {"HTTP_CODE_PAYLOAD_TOO_LARGE", 413}, + {"HTTP_CODE_URI_TOO_LARGE", 414}, + {"HTTP_CODE_UNSUPPORTED_MEDIA_TYPE", 415}, + {"HTTP_CODE_RANGE_NOT_SATISFIABLE", 416}, + {"HTTP_CODE_EXPECTATION_FAILED", 417}, + {"HTTP_CODE_IM_A_TEAPOT", 418}, + {"HTTP_CODE_MISDIRECTED_REQUEST", 421}, + {"HTTP_CODE_UNPROCESSABLE_ENTITY", 422}, + {"HTTP_CODE_LOCKED", 423}, + {"HTTP_CODE_FAILED_DEPENDENCY", 424}, + {"HTTP_CODE_TOO_EARLY", 425}, + {"HTTP_CODE_UPGRADE_REQUIRED", 426}, + {"HTTP_CODE_PRECONDITION_REQUIRED", 428}, + {"HTTP_CODE_TOO_MANY_REQUESTS", 429}, + {"HTTP_CODE_REQ_HDR_FIELDS_TOO_LARGE",431}, + {"HTTP_CODE_UNAVAIL_4_LEGAL_REASONS", 451}, + {"HTTP_CODE_INTERNAL_SERVER_ERROR", 500}, + {"HTTP_CODE_NOT_IMPLEMENTED", 501}, + {"HTTP_CODE_BAD_GATEWAY", 502}, + {"HTTP_CODE_SERVICE_UNAVAILABLE", 503}, + {"HTTP_CODE_GATEWAY_TIMEOUT", 504}, + {"HTTP_CODE_HTTP_VER_NOT_SUPPORTED", 505}, + {"HTTP_CODE_VARIANT_ALSO_NEGOTIATES", 506}, + {"HTTP_CODE_INSUFFICIENT_STORAGE", 507}, + {"HTTP_CODE_LOOP_DETECTED", 508}, + {"HTTP_CODE_NOT_EXTENDED", 510}, + {"HTTP_CODE_NETWORK_AUTH_REQUIRED", 511} +}; typedef enum { MON_CMD_CREATE_DB, @@ -46,6 +117,18 @@ typedef enum { MON_CMD_CREATE_TB_DN, MON_CMD_CREATE_TB_ACCT_ROOT, MON_CMD_CREATE_TB_SLOWQUERY, + //followings are extension for taoskeeper + MON_CMD_CREATE_TB_CLUSTER, + MON_CMD_CREATE_MT_DNODES, + MON_CMD_CREATE_TB_DNODE, + MON_CMD_CREATE_MT_DISKS, + MON_CMD_CREATE_TB_DISKS, + MON_CMD_CREATE_MT_VGROUPS, + MON_CMD_CREATE_MT_LOGS, + MON_CMD_CREATE_TB_DNODE_LOG, + MON_CMD_CREATE_TB_GRANTS, + MON_CMD_CREATE_MT_RESTFUL, + MON_CMD_CREATE_TB_RESTFUL, MON_CMD_MAX } EMonCmd; @@ -61,17 +144,46 @@ typedef struct { int8_t cmdIndex; int8_t state; int8_t start; // enable/disable by mnode - int8_t quiting; // taosd is quiting + int8_t quiting; // taosd is quiting char sql[SQL_LENGTH + 1]; } SMonConn; +typedef struct { + SDnodeStatisInfo dInfo; + SVnodeStatisInfo vInfo; + float io_read; + float io_write; + float io_read_disk; + float io_write_disk; + int32_t monQueryReqCnt; + int32_t monSubmitReqCnt; +} SMonStat; + +static void *monHttpStatusHashTable; + static SMonConn tsMonitor = {0}; +static SMonStat tsMonStat = {{0}}; +static int32_t monQueryReqNum = 0, monSubmitReqNum = 0; +static bool monHasMnodeMaster = false; + static void monSaveSystemInfo(); +static void monSaveClusterInfo(); +static void monSaveDnodesInfo(); +static void monSaveVgroupsInfo(); +static void monSaveSlowQueryInfo(); +static void monSaveDisksInfo(); +static void monSaveGrantsInfo(); +static void monSaveHttpReqInfo(); +static void monGetSysStats(); static void *monThreadFunc(void *param); static void monBuildMonitorSql(char *sql, int32_t cmd); +static void monInitHttpStatusHashTable(); +static void monCleanupHttpStatusHashTable(); + extern int32_t (*monStartSystemFp)(); extern void (*monStopSystemFp)(); extern void (*monExecuteSQLFp)(char *sql); +extern char * strptime(const char *buf, const char *fmt, struct tm *tm); //make the compilation pass int32_t monInitSystem() { if (tsMonitor.ep[0] == 0) { @@ -84,6 +196,7 @@ int32_t monInitSystem() { tsMonitor.ep[i] = '_'; } } + monInitHttpStatusHashTable(); pthread_attr_t thAttr; pthread_attr_init(&thAttr); @@ -112,6 +225,31 @@ int32_t monStartSystem() { return 0; } +static void monInitHttpStatusHashTable() { + int32_t numOfEntries = tListLen(monHttpStatusTable); + monHttpStatusHashTable = taosHashInit(numOfEntries, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, false); + for (int32_t i = 0; i < numOfEntries; ++i) { + monHttpStatusTable[i].index = i; + SMonHttpStatus* pEntry = &monHttpStatusTable[i]; + taosHashPut(monHttpStatusHashTable, &monHttpStatusTable[i].code, sizeof(int32_t), + &pEntry, POINTER_BYTES); + } +} + +static void monCleanupHttpStatusHashTable() { + void* m = monHttpStatusHashTable; + if (m != NULL && atomic_val_compare_exchange_ptr(&monHttpStatusHashTable, m, 0) == m) { + taosHashCleanup(m); + } +} + +SMonHttpStatus *monGetHttpStatusHashTableEntry(int32_t code) { + if (monHttpStatusHashTable == NULL) { + return NULL; + } + return (SMonHttpStatus*)taosHashGet(monHttpStatusHashTable, &code, sizeof(int32_t)); +} + static void *monThreadFunc(void *param) { monDebug("starting to initialize monitor module ..."); setThreadName("monitor"); @@ -132,7 +270,7 @@ static void *monThreadFunc(void *param) { if (tsMonitor.start == 0) { continue; } - + if (dnodeGetDnodeId() <= 0) { monDebug("dnode not initialized, waiting for 3000 ms to start monitor module"); continue; @@ -173,6 +311,19 @@ static void *monThreadFunc(void *param) { if (tsMonitor.state == MON_STATE_INITED) { if (accessTimes % tsMonitorInterval == 0) { + monGetSysStats(); + //monSaveDnodesInfo has to be the first, as it calculates + //stats using monSubmitReqNum before any insertion from monitor + monSaveDnodesInfo(); + if (monHasMnodeMaster) { + //only mnode master will write cluster info + monSaveClusterInfo(); + } + monSaveVgroupsInfo(); + monSaveSlowQueryInfo(); + monSaveDisksInfo(); + monSaveGrantsInfo(); + monSaveHttpReqInfo(); monSaveSystemInfo(); } } @@ -193,9 +344,9 @@ static void monBuildMonitorSql(char *sql, int32_t cmd) { if (cmd == MON_CMD_CREATE_DB) { snprintf(sql, SQL_LENGTH, - "create database if not exists %s replica 1 days 10 keep %s cache %d " + "create database if not exists %s replica %d days 10 keep %s cache %d " "blocks %d precision 'us'", - tsMonitorDbName, keepValue, TSDB_MIN_CACHE_BLOCK_SIZE, TSDB_MIN_TOTAL_BLOCKS); + tsMonitorDbName, tsMonitorReplica, keepValue, TSDB_MIN_CACHE_BLOCK_SIZE, TSDB_MIN_TOTAL_BLOCKS); } else if (cmd == MON_CMD_CREATE_MT_DN) { snprintf(sql, SQL_LENGTH, "create table if not exists %s.dn(ts timestamp" @@ -204,7 +355,7 @@ static void monBuildMonitorSql(char *sql, int32_t cmd) { ", disk_used float, disk_total int" ", band_speed float" ", io_read float, io_write float" - ", req_http int, req_select int, req_insert int" + ", req_http bigint, req_select bigint, req_insert bigint" ") tags (dnodeid int, fqdn binary(%d))", tsMonitorDbName, TSDB_FQDN_LEN); } else if (cmd == MON_CMD_CREATE_TB_DN) { @@ -231,14 +382,96 @@ static void monBuildMonitorSql(char *sql, int32_t cmd) { tsMonitorDbName, TSDB_DEFAULT_USER); } else if (cmd == MON_CMD_CREATE_TB_SLOWQUERY) { snprintf(sql, SQL_LENGTH, - "create table if not exists %s.slowquery(ts timestamp, username " - "binary(%d), created_time timestamp, time bigint, sql binary(%d))", - tsMonitorDbName, TSDB_TABLE_FNAME_LEN - 1, TSDB_SLOW_QUERY_SQL_LEN); + "create table if not exists %s.slowquery(ts timestamp, query_id " + "binary(%d), username binary(%d), qid binary(%d), created_time timestamp, time bigint, end_point binary(%d), sql binary(%d))", + tsMonitorDbName, QUERY_ID_LEN, TSDB_TABLE_FNAME_LEN - 1, QUERY_ID_LEN, TSDB_EP_LEN, TSDB_SLOW_QUERY_SQL_LEN); } else if (cmd == MON_CMD_CREATE_TB_LOG) { snprintf(sql, SQL_LENGTH, "create table if not exists %s.log(ts timestamp, level tinyint, " "content binary(%d), ipaddr binary(%d))", tsMonitorDbName, LOG_LEN_STR, IP_LEN_STR); + } else if (cmd == MON_CMD_CREATE_TB_CLUSTER) { + snprintf(sql, SQL_LENGTH, + "create table if not exists %s.cluster_info(ts timestamp" + ", first_ep binary(%d), version binary(%d)" + ", master_uptime float, monitor_interval int" + ", dnodes_total int, dnodes_alive int" + ", mnodes_total int, mnodes_alive int" + ", vgroups_total int, vgroups_alive int" + ", vnodes_total int, vnodes_alive int" + ", connections_total int)", + tsMonitorDbName, TSDB_EP_LEN, TSDB_VERSION_LEN); + } else if (cmd == MON_CMD_CREATE_MT_DNODES) { + snprintf(sql, SQL_LENGTH, + "create table if not exists %s.dnodes_info(ts timestamp" + ", uptime float" + ", cpu_engine float, cpu_system float, cpu_cores int" + ", mem_engine float, mem_system float, mem_total float" + ", 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 bigint, req_http_rate float" + ", req_select bigint, req_select_rate float" + ", req_insert bigint, req_insert_success bigint, req_insert_rate float" + ", req_insert_batch bigint, req_insert_batch_success bigint, req_insert_batch_rate float" + ", errors bigint" + ", vnodes_num int" + ", masters int" + ", has_mnode bool" + ") tags (dnode_id int, dnode_ep binary(%d))", + tsMonitorDbName, TSDB_EP_LEN); + } else if (cmd == MON_CMD_CREATE_TB_DNODE) { + snprintf(sql, SQL_LENGTH, "create table if not exists %s.dnode_%d using %s.dnodes_info tags(%d, '%s')", tsMonitorDbName, + dnodeGetDnodeId(), tsMonitorDbName, dnodeGetDnodeId(), tsLocalEp); + } else if (cmd == MON_CMD_CREATE_MT_DISKS) { + snprintf(sql, SQL_LENGTH, + "create table if not exists %s.disks_info(ts timestamp" + ", datadir_l0_used float, datadir_l0_total float" + ", datadir_l1_used float, datadir_l1_total float" + ", datadir_l2_used float, datadir_l2_total float" + ") tags (dnode_id int, dnode_ep binary(%d))", + tsMonitorDbName, TSDB_EP_LEN); + } else if (cmd == MON_CMD_CREATE_TB_DISKS) { + snprintf(sql, SQL_LENGTH, "create table if not exists %s.disks_%d using %s.disks_info tags(%d, '%s')", tsMonitorDbName, + dnodeGetDnodeId(), tsMonitorDbName, dnodeGetDnodeId(), tsLocalEp); + } else if (cmd == MON_CMD_CREATE_MT_VGROUPS) { + snprintf(sql, SQL_LENGTH, + "create table if not exists %s.vgroups_info(ts timestamp" + ", database_name binary(%d)" + ", tables_num int, status binary(%d)" + ", online_vnodes tinyint" + ", dnode_ids binary(%d), dnode_roles binary(%d)" + ") tags (vgroup_id int)", + tsMonitorDbName, TSDB_DB_NAME_LEN, VGROUP_STATUS_LEN, + DNODE_INFO_LEN, DNODE_INFO_LEN); + } else if (cmd == MON_CMD_CREATE_MT_LOGS) { + snprintf(sql, SQL_LENGTH, + "create table if not exists %s.logs(ts timestamp, level tinyint, " + "content binary(%d)) tags (dnode_id int, dnode_ep binary(%d))", + tsMonitorDbName, LOG_LEN_STR, TSDB_EP_LEN); + } else if (cmd == MON_CMD_CREATE_TB_DNODE_LOG) { + snprintf(sql, SQL_LENGTH, "create table if not exists %s.dnode_%d_log using %s.logs tags(%d, '%s')", tsMonitorDbName, + dnodeGetDnodeId(), tsMonitorDbName, dnodeGetDnodeId(), tsLocalEp); + } else if (cmd == MON_CMD_CREATE_TB_GRANTS) { + snprintf(sql, SQL_LENGTH, + "create table if not exists %s.grants_info(ts timestamp" + ", expire_time int, timeseries_used int, timeseries_total int)", + tsMonitorDbName); + } else if (cmd == MON_CMD_CREATE_MT_RESTFUL) { + int pos = snprintf(sql, SQL_LENGTH, + "create table if not exists %s.restful_info(ts timestamp", tsMonitorDbName); + for (int i = 0; i < tListLen(monHttpStatusTable); ++i) { + pos += snprintf(sql + pos, SQL_LENGTH, ", `%s(%d)` int", + monHttpStatusTable[i].name, + monHttpStatusTable[i].code); + } + snprintf(sql + pos, SQL_LENGTH, + ") tags (dnode_id int, dnode_ep binary(%d))", + TSDB_EP_LEN); + } else if (cmd == MON_CMD_CREATE_TB_RESTFUL) { + snprintf(sql, SQL_LENGTH, "create table if not exists %s.restful_%d using %s.restful_info tags(%d, '%s')", tsMonitorDbName, + dnodeGetDnodeId(), tsMonitorDbName, dnodeGetDnodeId(), tsLocalEp); } sql[SQL_LENGTH] = 0; @@ -262,9 +495,25 @@ void monCleanupSystem() { taos_close(tsMonitor.conn); tsMonitor.conn = NULL; } + monCleanupHttpStatusHashTable(); 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"); + } + + tsMonStat.dInfo = dnodeGetStatisInfo(); + tsMonStat.vInfo = vnodeGetStatisInfo(); + + tsMonStat.monQueryReqCnt = monFetchQueryReqCnt(); + tsMonStat.monSubmitReqCnt = monFetchSubmitReqCnt(); +} + // unit is MB static int32_t monBuildMemorySql(char *sql) { float sysMemoryUsedMB = 0; @@ -279,7 +528,7 @@ static int32_t monBuildMemorySql(char *sql) { monDebug("failed to get proc memory info"); } - return sprintf(sql, ", %f, %f, %d", procMemoryUsedMB, sysMemoryUsedMB, tsTotalMemoryMB); + return snprintf(sql, SQL_LENGTH, ", %f, %f, %d", procMemoryUsedMB, sysMemoryUsedMB, tsTotalMemoryMB); } // unit is % @@ -294,12 +543,12 @@ static int32_t monBuildCpuSql(char *sql) { sysCpuUsage = procCpuUsage + 0.1f; } - return sprintf(sql, ", %f, %f, %d", procCpuUsage, sysCpuUsage, tsNumOfCores); + return snprintf(sql, SQL_LENGTH, ", %f, %f, %d", procCpuUsage, sysCpuUsage, tsNumOfCores); } // unit is GB static int32_t monBuildDiskSql(char *sql) { - return sprintf(sql, ", %f, %d", tsUsedDataDirGB, (int32_t)tsTotalDataDirGB); + return snprintf(sql, SQL_LENGTH, ", %f, %d", tsUsedDataDirGB, (int32_t)tsTotalDataDirGB); } // unit is Kb @@ -310,22 +559,20 @@ static int32_t monBuildBandSql(char *sql) { monDebug("failed to get bandwidth speed"); } - return sprintf(sql, ", %f", bandSpeedKb); + return snprintf(sql, SQL_LENGTH, ", %f", bandSpeedKb); } static int32_t monBuildReqSql(char *sql) { - SStatisInfo info = dnodeGetStatisInfo(); - return sprintf(sql, ", %d, %d, %d)", info.httpReqNum, info.queryReqNum, info.submitReqNum); + SDnodeStatisInfo info = tsMonStat.dInfo; + return snprintf(sql, SQL_LENGTH, ", %"PRId64", %"PRId64", %"PRId64")", info.httpReqNum, info.queryReqNum, info.submitReqNum); } 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); + return snprintf(sql, SQL_LENGTH, ", %f, %f", readKB, writeKB); } static void monSaveSystemInfo() { @@ -347,15 +594,773 @@ static void monSaveSystemInfo() { if (code != 0) { monError("failed to save system info, reason:%s, sql:%s", tstrerror(code), tsMonitor.sql); } else { + monIncSubmitReqCnt(); monDebug("successfully to save system info, sql:%s", tsMonitor.sql); } } +static int32_t monGetRowElemCharLen(TAOS_FIELD field, char *rowElem) { + int32_t charLen = varDataLen(rowElem - VARSTR_HEADER_SIZE); + if (field.type == TSDB_DATA_TYPE_BINARY) { + assert(charLen <= field.bytes && charLen >= 0); + } else { + assert(charLen <= field.bytes * TSDB_NCHAR_SIZE && charLen >= 0); + } + + return charLen; +} + +static int32_t monBuildFirstEpSql(char *sql) { + return snprintf(sql, SQL_LENGTH, ", \"%s\"", tsFirst); +} + +static int32_t monBuildVersionSql(char *sql) { + return snprintf(sql, SQL_LENGTH, ", \"%s\"", version); +} + +static int32_t monBuildMasterUptimeSql(char *sql) { + int64_t masterUptime = 0; + TAOS_RES *result = taos_query(tsMonitor.conn, "show mnodes"); + + TAOS_ROW row; + int32_t num_fields = taos_num_fields(result); + TAOS_FIELD *fields = taos_fetch_fields(result); + + while ((row = taos_fetch_row(result))) { + for (int i = 0; i < num_fields; ++i) { + if (strcmp(fields[i].name, "role") == 0 && strcmp((char *)row[i], "master") == 0) { + if (strcmp(fields[i + 1].name, "role_time") == 0) { + int64_t now = taosGetTimestamp(TSDB_TIME_PRECISION_MILLI); + //master uptime in seconds + masterUptime = (now - *(int64_t *)row[i + 1]) / 1000; + } + } + } + } + + taos_free_result(result); + + return snprintf(sql, SQL_LENGTH, ", %" PRId64, masterUptime); +} + +static int32_t monBuildMonIntervalSql(char *sql) { + return snprintf(sql, SQL_LENGTH, ", %d", tsMonitorInterval); +} + +static int32_t monBuildDnodesTotalSql(char *sql) { + int32_t totalDnodes = 0, totalDnodesAlive = 0; + TAOS_RES *result = taos_query(tsMonitor.conn, "show dnodes"); + int32_t code = taos_errno(result); + if (code != TSDB_CODE_SUCCESS) { + monError("failed to execute cmd: show dnodes, reason:%s", tstrerror(code)); + } + + TAOS_ROW row; + int32_t num_fields = taos_num_fields(result); + TAOS_FIELD *fields = taos_fetch_fields(result); + + while ((row = taos_fetch_row(result))) { + totalDnodes++; + for (int i = 0; i < num_fields; ++i) { + if (strcmp(fields[i].name, "status") == 0) { + int32_t charLen = monGetRowElemCharLen(fields[i], (char *)row[i]); + if (strncmp((char *)row[i], "ready", charLen) == 0) { + totalDnodesAlive++; + } + } + } + } + + taos_free_result(result); + + return snprintf(sql, SQL_LENGTH, ", %d, %d", totalDnodes, totalDnodesAlive); +} + +static int32_t monBuildMnodesTotalSql(char *sql) { + int32_t totalMnodes = 0, totalMnodesAlive= 0; + TAOS_RES *result = taos_query(tsMonitor.conn, "show mnodes"); + int32_t code = taos_errno(result); + if (code != TSDB_CODE_SUCCESS) { + monError("failed to execute cmd: show mnodes, reason:%s", tstrerror(code)); + } + + TAOS_ROW row; + int32_t num_fields = taos_num_fields(result); + TAOS_FIELD *fields = taos_fetch_fields(result); + + while ((row = taos_fetch_row(result))) { + totalMnodes++; + for (int i = 0; i < num_fields; ++i) { + if (strcmp(fields[i].name, "role") == 0) { + int32_t charLen = monGetRowElemCharLen(fields[i], (char *)row[i]); + if (strncmp((char *)row[i], "master", charLen) == 0 || + strncmp((char *)row[i], "slave", charLen) == 0) { + totalMnodesAlive += 1; + } + } + } + } + + taos_free_result(result); + + return snprintf(sql, SQL_LENGTH, ", %d, %d", totalMnodes, totalMnodesAlive); +} + + +static int32_t monGetVgroupsTotalStats(char *dbName, int32_t *totalVgroups, + int32_t *totalVgroupsAlive) { + char subsql[TSDB_DB_NAME_LEN + 14]; + memset(subsql, 0, sizeof(subsql)); + snprintf(subsql, TSDB_DB_NAME_LEN + 13, "show %s.vgroups", dbName); + TAOS_RES *result = taos_query(tsMonitor.conn, subsql); + int32_t code = taos_errno(result); + if (code != TSDB_CODE_SUCCESS) { + monError("failed to execute cmd: show %s.vgroups, reason:%s", dbName, tstrerror(code)); + } + + TAOS_ROW row; + int32_t num_fields = taos_num_fields(result); + TAOS_FIELD *fields = taos_fetch_fields(result); + + while ((row = taos_fetch_row(result))) { + *totalVgroups += 1; + for (int i = 0; i < num_fields; ++i) { + if (strcmp(fields[i].name, "status") == 0) { + int32_t charLen = monGetRowElemCharLen(fields[i], (char *)row[i]); + if (strncmp((char *)row[i], "ready", charLen) == 0) { + *totalVgroupsAlive += 1; + } + } + } + } + taos_free_result(result); + + return 0; +} + +static int32_t monBuildVgroupsTotalSql(char *sql) { + int32_t totalVgroups = 0, totalVgroupsAlive = 0; + TAOS_RES *result = taos_query(tsMonitor.conn, "show databases"); + int32_t code = taos_errno(result); + if (code != TSDB_CODE_SUCCESS) { + monError("failed to execute cmd: show databases, reason:%s", tstrerror(code)); + } + + TAOS_ROW row; + int32_t num_fields = taos_num_fields(result); + TAOS_FIELD *fields = taos_fetch_fields(result); + + while ((row = taos_fetch_row(result))) { + for (int i = 0; i < num_fields; ++i) { + //database name + if (strcmp(fields[i].name, "name") == 0) { + monGetVgroupsTotalStats((char *)row[i], &totalVgroups, &totalVgroupsAlive); + } + } + } + + taos_free_result(result); + + return snprintf(sql, SQL_LENGTH, ", %d, %d", totalVgroups, totalVgroupsAlive); +} + +static int32_t monGetVnodesTotalStats(char *ep, int32_t *totalVnodes, + int32_t *totalVnodesAlive) { + char subsql[TSDB_EP_LEN + 15]; + memset(subsql, 0, sizeof(subsql)); + snprintf(subsql, TSDB_EP_LEN, "show vnodes \"%s\"", ep); + TAOS_RES *result = taos_query(tsMonitor.conn, subsql); + int32_t code = taos_errno(result); + if (code != TSDB_CODE_SUCCESS) { + monError("failed to execute cmd: show vnodes \"%s\", reason:%s", ep, tstrerror(code)); + } + + TAOS_ROW row; + int32_t num_fields = taos_num_fields(result); + TAOS_FIELD *fields = taos_fetch_fields(result); + + while ((row = taos_fetch_row(result))) { + *totalVnodes += 1; + for (int i = 0; i < num_fields; ++i) { + if (strcmp(fields[i].name, "status") == 0) { + int32_t charLen = monGetRowElemCharLen(fields[i], (char *)row[i]); + if (strncmp((char *)row[i], "master", charLen) == 0 || + strncmp((char *)row[i], "slave", charLen) == 0) { + *totalVnodesAlive += 1; + } + } + } + } + taos_free_result(result); + + return 0; +} + +static int32_t monBuildVnodesTotalSql(char *sql) { + int32_t totalVnodes = 0, totalVnodesAlive = 0; + TAOS_RES *result = taos_query(tsMonitor.conn, "show dnodes"); + int32_t code = taos_errno(result); + if (code != TSDB_CODE_SUCCESS) { + monError("failed to execute cmd: show dnodes, reason:%s", tstrerror(code)); + } + + TAOS_ROW row; + int32_t num_fields = taos_num_fields(result); + TAOS_FIELD *fields = taos_fetch_fields(result); + + while ((row = taos_fetch_row(result))) { + for (int i = 0; i < num_fields; ++i) { + //database name + if (strcmp(fields[i].name, "end_point") == 0) { + monGetVnodesTotalStats((char *)row[i], &totalVnodes, &totalVnodesAlive); + } + } + } + + taos_free_result(result); + + return snprintf(sql, SQL_LENGTH, ", %d, %d", totalVnodes, totalVnodesAlive); +} + +static int32_t monBuildConnsTotalSql(char *sql) { + int32_t totalConns = 0; + TAOS_RES *result = taos_query(tsMonitor.conn, "show connections"); + TAOS_ROW row; + + int32_t code = taos_errno(result); + if (code != TSDB_CODE_SUCCESS) { + monError("failed to execute cmd: show connections, reason:%s", tstrerror(code)); + } + + while ((row = taos_fetch_row(result))) { + totalConns++; + } + + taos_free_result(result); + return snprintf(sql, SQL_LENGTH, ", %d)", totalConns); +} + +static int32_t monBuildDnodeUptimeSql(char *sql) { + int64_t dnodeUptime = 0; + TAOS_RES *result = taos_query(tsMonitor.conn, "show dnodes"); + int32_t code = taos_errno(result); + if (code != TSDB_CODE_SUCCESS) { + monError("failed to execute cmd: show dnodes, reason:%s", tstrerror(code)); + } + + TAOS_ROW row; + int32_t num_fields = taos_num_fields(result); + TAOS_FIELD *fields = taos_fetch_fields(result); + + bool is_self_ep = false; + while ((row = taos_fetch_row(result))) { + if (is_self_ep) { + break; + } + 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) == 0) { + is_self_ep = true; + } + } + if (strcmp(fields[i].name, "create_time") == 0) { + if (is_self_ep) { + int64_t now = taosGetTimestamp(TSDB_TIME_PRECISION_MILLI); + //dnodes uptime in seconds + dnodeUptime = (now - *(int64_t *)row[i]) / 1000; + } + } + } + } + + taos_free_result(result); + + return snprintf(sql, SQL_LENGTH, ", %" PRId64, dnodeUptime); +} + +static int32_t monBuildDnodeIoSql(char *sql) { + float rcharKB = 0, wcharKB = 0; + float rbyteKB = 0, wbyteKB = 0; + rcharKB = tsMonStat.io_read; + wcharKB = tsMonStat.io_write; + rbyteKB = tsMonStat.io_read_disk; + wbyteKB = tsMonStat.io_write_disk; + + return snprintf(sql, SQL_LENGTH, ", %f, %f, %f, %f", rcharKB / 1024, wcharKB / 1024, + rbyteKB / 1024, wbyteKB / 1024); +} + +static int32_t monBuildNetworkIOSql(char *sql) { + float netInKb = 0, netOutKb = 0; + bool suc = taosGetNetworkIO(&netInKb, &netOutKb); + if (!suc) { + monDebug("failed to get network I/O info"); + } + + return snprintf(sql, SQL_LENGTH, ", %f, %f", netInKb / 1024, + netOutKb / 1024); +} + +static int32_t monBuildDnodeReqSql(char *sql) { + int64_t queryReqNum = tsMonStat.dInfo.queryReqNum - tsMonStat.monQueryReqCnt; + int64_t submitReqNum = tsMonStat.dInfo.submitReqNum; + int64_t submitRowNum = tsMonStat.vInfo.submitRowNum; + int64_t submitReqSucNum = tsMonStat.vInfo.submitReqSucNum; + int64_t submitRowSucNum = tsMonStat.vInfo.submitRowSucNum; + + float interval = (float)(tsMonitorInterval * 1.0); + float httpReqRate = tsMonStat.dInfo.httpReqNum / interval; + float queryReqRate = queryReqNum / interval; + float submitReqRate = submitReqNum / interval; + float submitRowRate = submitRowNum / interval; + + return snprintf(sql, SQL_LENGTH, ", %"PRId64", %f, %"PRId64", %f, %"PRId64", %"PRId64", %f, %"PRId64", %"PRId64", %f", + tsMonStat.dInfo.httpReqNum, httpReqRate, + queryReqNum, queryReqRate, + submitRowNum, submitRowSucNum, submitRowRate, + submitReqNum, submitReqSucNum, submitReqRate); +} + +static int32_t monBuildDnodeErrorsSql(char *sql) { + int64_t dnode_err = dnodeGetDnodeError(); + return snprintf(sql, SQL_LENGTH, ", %"PRId64, dnode_err); +} + +static int32_t monBuildDnodeVnodesSql(char *sql) { + int32_t vnodeNum = 0, masterNum = 0; + char sqlStr[TSDB_EP_LEN + 15]; + memset(sqlStr, 0, sizeof(sqlStr)); + snprintf(sqlStr, TSDB_EP_LEN + 14, "show vnodes \"%s\"", tsLocalEp); + TAOS_RES *result = taos_query(tsMonitor.conn, sqlStr); + int32_t code = taos_errno(result); + if (code != TSDB_CODE_SUCCESS) { + monError("failed to execute cmd: show vnodes \"%s\", reason:%s", tsLocalEp, tstrerror(code)); + } + + TAOS_ROW row; + int32_t num_fields = taos_num_fields(result); + TAOS_FIELD *fields = taos_fetch_fields(result); + + while ((row = taos_fetch_row(result))) { + vnodeNum += 1; + for (int i = 0; i < num_fields; ++i) { + if (strcmp(fields[i].name, "status") == 0) { + int32_t charLen = monGetRowElemCharLen(fields[i], (char *)row[i]); + if (strncmp((char *)row[i], "master", charLen) == 0) { + masterNum += 1; + } + } + } + } + taos_free_result(result); + + return snprintf(sql, SQL_LENGTH, ", %d, %d", vnodeNum, masterNum); +} + +static int32_t monBuildDnodeMnodeSql(char *sql) { + bool has_mnode = false, has_mnode_row; + TAOS_RES *result = taos_query(tsMonitor.conn, "show mnodes"); + int32_t code = taos_errno(result); + if (code != TSDB_CODE_SUCCESS) { + monError("failed to execute cmd: show mnodes, reason:%s", tstrerror(code)); + } + + TAOS_ROW row; + int32_t num_fields = taos_num_fields(result); + TAOS_FIELD *fields = taos_fetch_fields(result); + + while ((row = taos_fetch_row(result))) { + has_mnode_row = false; + 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) == 0) { + has_mnode = true; + has_mnode_row = true; + } + } else if (strcmp(fields[i].name, "role") == 0) { + int32_t charLen = monGetRowElemCharLen(fields[i], (char *)row[i]); + if (strncmp((char *)row[i], "master", charLen) == 0) { + if (has_mnode_row) { + monHasMnodeMaster = true; + } + } + } + } + } + taos_free_result(result); + + return snprintf(sql, SQL_LENGTH, ", %s)", has_mnode ? "true" : "false"); +} + +static int32_t monBuildDnodeDiskSql(char *sql) { + float taosdDataDirGB = 0; + return snprintf(sql, SQL_LENGTH, ", %f, %f, %f", taosdDataDirGB, tsUsedDataDirGB, tsTotalDataDirGB); +} + +static int32_t monBuildDiskTierSql(char *sql) { + const int8_t numTiers = 3; + const double unit = 1024 * 1024 * 1024; + SFSMeta fsMeta; + STierMeta* tierMetas = calloc(numTiers, sizeof(STierMeta)); + tfsUpdateInfo(&fsMeta, tierMetas, numTiers); + int32_t pos = 0; + + for (int i = 0; i < numTiers; ++i) { + pos += snprintf(sql + pos, SQL_LENGTH, ", %f, %f", (float)(tierMetas[i].used / unit), (float)(tierMetas[i].size / unit)); + } + pos += snprintf(sql + pos, SQL_LENGTH, ")"); + + free(tierMetas); + + return pos; +} + +static void monSaveClusterInfo() { + int64_t ts = taosGetTimestampUs(); + char * sql = tsMonitor.sql; + int32_t pos = snprintf(sql, SQL_LENGTH, "insert into %s.cluster_info values(%" PRId64, tsMonitorDbName, ts); + + pos += monBuildFirstEpSql(sql + pos); + pos += monBuildVersionSql(sql + pos); + pos += monBuildMasterUptimeSql(sql + pos); + pos += monBuildMonIntervalSql(sql + pos); + pos += monBuildDnodesTotalSql(sql + pos); + pos += monBuildMnodesTotalSql(sql + pos); + pos += monBuildVgroupsTotalSql(sql + pos); + pos += monBuildVnodesTotalSql(sql + pos); + pos += monBuildConnsTotalSql(sql + pos); + + monDebug("save cluster, sql:%s", sql); + + void *res = taos_query(tsMonitor.conn, tsMonitor.sql); + int32_t code = taos_errno(res); + taos_free_result(res); + + if (code != 0) { + monError("failed to save cluster info, reason:%s, sql:%s", tstrerror(code), tsMonitor.sql); + } else { + monIncSubmitReqCnt(); + monDebug("successfully to save cluster info, sql:%s", tsMonitor.sql); + } +} + +static void monSaveDnodesInfo() { + int64_t ts = taosGetTimestampUs(); + char * sql = tsMonitor.sql; + int64_t intervalUs = tsMonitorInterval * 1000000; + ts = ts / intervalUs * intervalUs; //To align timestamp to integer multiples of monitor interval + int32_t pos = snprintf(sql, SQL_LENGTH, "insert into %s.dnode_%d values(%" PRId64, tsMonitorDbName, dnodeGetDnodeId(), ts); + + pos += monBuildDnodeUptimeSql(sql + pos); + pos += monBuildCpuSql(sql + pos); + pos += monBuildMemorySql(sql + pos); + pos += monBuildDnodeDiskSql(sql + pos); + pos += monBuildNetworkIOSql(sql + pos); + pos += monBuildDnodeIoSql(sql + pos); + pos += monBuildDnodeReqSql(sql + pos); + pos += monBuildDnodeErrorsSql(sql + pos); + pos += monBuildDnodeVnodesSql(sql + pos); + pos += monBuildDnodeMnodeSql(sql + pos); + + monDebug("save dnodes, sql:%s", sql); + + void *res = taos_query(tsMonitor.conn, tsMonitor.sql); + int32_t code = taos_errno(res); + taos_free_result(res); + + if (code != 0) { + monError("failed to save dnode_%d info, reason:%s, sql:%s", dnodeGetDnodeId(), tstrerror(code), tsMonitor.sql); + } else { + monIncSubmitReqCnt(); + monDebug("successfully to save dnode_%d info, sql:%s", dnodeGetDnodeId(), tsMonitor.sql); + } +} + + +static int32_t checkCreateVgroupTable(int32_t vgId) { + char subsql[256]; + bool create_table = false; + int32_t code = TSDB_CODE_SUCCESS; + + memset(subsql, 0, sizeof(subsql)); + snprintf(subsql, 255, "describe %s.vgroup_%d", tsMonitorDbName, vgId); + + TAOS_RES *result = taos_query(tsMonitor.conn, subsql); + code = taos_errno(result); + if (code != 0) { + create_table = true; + snprintf(subsql, sizeof(subsql), "create table if not exists %s.vgroup_%d using %s.vgroups_info tags(%d)", + tsMonitorDbName, vgId, tsMonitorDbName, vgId); + monError("table vgroup_%d not exist, create table vgroup_%d", vgId, vgId); + } + taos_free_result(result); + + if (create_table == true) { + result = taos_query(tsMonitor.conn, subsql); + code = taos_errno(result); + taos_free_result(result); + } + + return code; +} + +static uint32_t monBuildVgroupsInfoSql(char *sql, char *dbName) { + char v_dnode_ids[256], v_dnode_status[1024]; + int64_t ts = taosGetTimestampUs(); + + memset(sql, 0, SQL_LENGTH + 1); + snprintf(sql, SQL_LENGTH, "show %s.vgroups", dbName); + TAOS_RES *result = taos_query(tsMonitor.conn, sql); + int32_t code = taos_errno(result); + if (code != TSDB_CODE_SUCCESS) { + monError("failed to execute cmd: show %s.vgroups, reason:%s", dbName, tstrerror(code)); + } + + TAOS_ROW row; + int32_t num_fields = taos_num_fields(result); + TAOS_FIELD *fields = taos_fetch_fields(result); + + while ((row = taos_fetch_row(result))) { + int32_t vgId; + int32_t pos = 0; + + for (int i = 0; i < num_fields; ++i) { + const char *v_dnode_str = strchr(fields[i].name, '_'); + if (strcmp(fields[i].name, "vgId") == 0) { + vgId = *(int32_t *)row[i]; + if (checkCreateVgroupTable(vgId) == TSDB_CODE_SUCCESS) { + memset(sql, 0, SQL_LENGTH + 1); + pos += snprintf(sql, SQL_LENGTH, "insert into %s.vgroup_%d values(%" PRId64 ", \"%s\"", + tsMonitorDbName, vgId, ts, dbName); + } else { + return TSDB_CODE_SUCCESS; + } + } else if (strcmp(fields[i].name, "tables") == 0) { + pos += snprintf(sql + pos, SQL_LENGTH, ", %d", *(int32_t *)row[i]); + + } else if (strcmp(fields[i].name, "status") == 0) { + pos += snprintf(sql + pos, SQL_LENGTH, ", \"%s\"", (char *)row[i]); + } else if (strcmp(fields[i].name, "onlines") == 0) { + pos += snprintf(sql + pos, SQL_LENGTH, ", %d", *(int32_t *)row[i]); + } else if (v_dnode_str && strcmp(v_dnode_str, "_dnode") == 0) { + snprintf(v_dnode_ids, sizeof(v_dnode_ids), "%d;", *(int16_t *)row[i]); + } else if (v_dnode_str && strcmp(v_dnode_str, "_status") == 0) { + snprintf(v_dnode_status, sizeof(v_dnode_status), "%s;", (char *)row[i]); + } else if (strcmp(fields[i].name, "compacting") == 0) { + //flush dnode_ids and dnode_role in to sql + pos += snprintf(sql + pos, SQL_LENGTH, ", \"%s\", \"%s\")", v_dnode_ids, v_dnode_status); + } + } + monDebug("save vgroups, sql:%s", sql); + TAOS_RES *res = taos_query(tsMonitor.conn, sql); + code = taos_errno(res); + taos_free_result(res); + if (code != 0) { + monError("failed to save vgroup_%d info, reason:%s, sql:%s", vgId, tstrerror(code), tsMonitor.sql); + } else { + monIncSubmitReqCnt(); + monDebug("successfully to save vgroup_%d info, sql:%s", vgId, tsMonitor.sql); + } + } + taos_free_result(result); + + return TSDB_CODE_SUCCESS; +} + +static void monSaveVgroupsInfo() { + char * sql = tsMonitor.sql; + TAOS_RES *result = taos_query(tsMonitor.conn, "show databases"); + int32_t code = taos_errno(result); + if (code != TSDB_CODE_SUCCESS) { + monError("failed to execute cmd: show databases, reason:%s", tstrerror(code)); + } + + TAOS_ROW row; + int32_t num_fields = taos_num_fields(result); + TAOS_FIELD *fields = taos_fetch_fields(result); + + while ((row = taos_fetch_row(result))) { + for (int i = 0; i < num_fields; ++i) { + //database name + if (strcmp(fields[i].name, "name") == 0) { + monBuildVgroupsInfoSql(sql, (char *)row[i]); + } + } + } + + taos_free_result(result); +} + +static void monSaveSlowQueryInfo() { + int64_t ts = taosGetTimestampUs(); + char * sql = tsMonitor.sql; + int32_t pos = snprintf(sql, SQL_LENGTH, "insert into %s.slowquery values(%" PRId64, tsMonitorDbName, ts); + bool has_slowquery = false; + + TAOS_RES *result = taos_query(tsMonitor.conn, "show queries"); + int32_t code = taos_errno(result); + if (code != TSDB_CODE_SUCCESS) { + monError("failed to execute cmd: show queries, reason:%s", tstrerror(code)); + } + + TAOS_ROW row; + int32_t num_fields = taos_num_fields(result); + TAOS_FIELD *fields = taos_fetch_fields(result); + + while ((row = taos_fetch_row(result))) { + for (int i = 0; i < num_fields; ++i) { + if (strcmp(fields[i].name, "query_id") == 0) { + has_slowquery = true; + pos += snprintf(sql + pos, SQL_LENGTH, ", \"%s\"", (char *)row[i]); + } else if (strcmp(fields[i].name, "user") == 0) { + pos += snprintf(sql + pos, SQL_LENGTH, ", \"%s\"", (char *)row[i]); + } else if (strcmp(fields[i].name, "qid") == 0) { + pos += snprintf(sql + pos, SQL_LENGTH, ", \"%s\"", (char *)row[i]); + } else if (strcmp(fields[i].name, "created_time") == 0) { + int64_t create_time = *(int64_t *)row[i]; + create_time = convertTimePrecision(create_time, TSDB_TIME_PRECISION_MILLI, TSDB_TIME_PRECISION_MICRO); + pos += snprintf(sql + pos, SQL_LENGTH, ", %" PRId64 "", create_time); + } else if (strcmp(fields[i].name, "time") == 0) { + pos += snprintf(sql + pos, SQL_LENGTH, ", %" PRId64 "", *(int64_t *)row[i]); + } else if (strcmp(fields[i].name, "ep") == 0) { + pos += snprintf(sql + pos, SQL_LENGTH, ", \"%s\"", (char *)row[i]); + } else if (strcmp(fields[i].name, "sql") == 0) { + pos += snprintf(sql + pos, SQL_LENGTH, ", \"%s\")", (char *)row[i]); + } + } + } + + monDebug("save slow query, sql:%s", sql); + taos_free_result(result); + if (!has_slowquery) { + return; + } + void *res = taos_query(tsMonitor.conn, tsMonitor.sql); + code = taos_errno(res); + taos_free_result(res); + + if (code != 0) { + monError("failed to save slowquery info, reason:%s, sql:%s", tstrerror(code), tsMonitor.sql); + } else { + monIncSubmitReqCnt(); + monDebug("successfully to save slowquery info, sql:%s", tsMonitor.sql); + } + +} + +static void monSaveDisksInfo() { + int64_t ts = taosGetTimestampUs(); + char * sql = tsMonitor.sql; + int32_t pos = snprintf(sql, SQL_LENGTH, "insert into %s.disks_%d values(%" PRId64, tsMonitorDbName, dnodeGetDnodeId(), ts); + + monBuildDiskTierSql(sql + pos); + + monDebug("save disk, sql:%s", sql); + + void *res = taos_query(tsMonitor.conn, tsMonitor.sql); + int32_t code = taos_errno(res); + taos_free_result(res); + + if (code != 0) { + monError("failed to save disks_%d info, reason:%s, sql:%s", dnodeGetDnodeId(), tstrerror(code), tsMonitor.sql); + } else { + monIncSubmitReqCnt(); + monDebug("successfully to save disks_%d info, sql:%s", dnodeGetDnodeId(), tsMonitor.sql); + } +} + +static void monSaveGrantsInfo() { + int64_t ts = taosGetTimestampUs(); + char * sql = tsMonitor.sql; + int32_t pos = snprintf(sql, SQL_LENGTH, "insert into %s.grants_info values(%" PRId64, tsMonitorDbName, ts); + + TAOS_RES *result = taos_query(tsMonitor.conn, "show grants"); + int32_t code = taos_errno(result); + if (code != TSDB_CODE_SUCCESS) { + taos_free_result(result); + return; + } + + TAOS_ROW row; + int32_t num_fields = taos_num_fields(result); + TAOS_FIELD *fields = taos_fetch_fields(result); + + while ((row = taos_fetch_row(result))) { + for (int i = 0; i < num_fields; ++i) { + if (strcmp(fields[i].name, "expire time") == 0) { + char *expStr = (char *)row[i]; + if (expStr[0] == 'u') { + pos += snprintf(sql + pos, SQL_LENGTH, ", NULL"); + } else { + struct tm expTime = {0}; + strptime((char *)row[i], "%Y-%m-%d %H:%M:%S", &expTime); + int32_t expTimeSec = (int32_t)mktime(&expTime); + pos += snprintf(sql + pos, SQL_LENGTH, ", %d", expTimeSec - taosGetTimestampSec()); + } + } else if (strcmp(fields[i].name, "timeseries") == 0) { + char *timeseries = (char *)row[i]; + if (timeseries[0] == 'u') { + pos += snprintf(sql + pos, SQL_LENGTH, ", NULL, NULL)"); + } else { + int32_t timeseries_used = strtol(timeseries, NULL, 10); + timeseries = strchr(timeseries, '/'); + int32_t timeseries_total = strtol(timeseries + 1, NULL, 10); + pos += snprintf(sql + pos, SQL_LENGTH, ", %d, %d)", timeseries_used, timeseries_total); + } + } + } + } + + monDebug("save grants, sql:%s", sql); + taos_free_result(result); + + void *res = taos_query(tsMonitor.conn, tsMonitor.sql); + code = taos_errno(res); + taos_free_result(res); + + if (code != 0) { + monError("failed to save grants info, reason:%s, sql:%s", tstrerror(code), tsMonitor.sql); + } else { + monIncSubmitReqCnt(); + monDebug("successfully to save grants info, sql:%s", tsMonitor.sql); + } + +} + +static void monSaveHttpReqInfo() { + int64_t ts = taosGetTimestampUs(); + char * sql = tsMonitor.sql; + int32_t pos = snprintf(sql, SQL_LENGTH, "insert into %s.restful_%d values(%" PRId64, tsMonitorDbName, dnodeGetDnodeId(), ts); + + for (int32_t i = 0; i < tListLen(monHttpStatusTable); ++i) { + int32_t status = dnodeGetHttpStatusInfo(i); + pos += snprintf(sql + pos, SQL_LENGTH, ", %d", status); + } + pos += snprintf(sql + pos, SQL_LENGTH, ")"); + dnodeClearHttpStatusInfo(); + + monDebug("save http req, sql:%s", sql); + + void *res = taos_query(tsMonitor.conn, tsMonitor.sql); + int32_t code = taos_errno(res); + taos_free_result(res); + + if (code != 0) { + monError("failed to save restful_%d info, reason:%s, sql:%s", dnodeGetDnodeId(), tstrerror(code), tsMonitor.sql); + } else { + monIncSubmitReqCnt(); + monDebug("successfully to save restful_%d info, sql:%s", dnodeGetDnodeId(), tsMonitor.sql); + } +} + static void monExecSqlCb(void *param, TAOS_RES *result, int32_t code) { int32_t c = taos_errno(result); if (c != TSDB_CODE_SUCCESS) { monError("save %s failed, reason:%s", (char *)param, tstrerror(c)); } else { + monIncSubmitReqCnt(); int32_t rows = taos_affected_rows(result); monDebug("save %s succ, rows:%d", (char *)param, rows); } @@ -367,7 +1372,7 @@ void monSaveAcctLog(SAcctMonitorObj *pMon) { if (tsMonitor.state != MON_STATE_INITED) return; char sql[1024] = {0}; - sprintf(sql, + snprintf(sql, 1023, "insert into %s.acct_%s using %s.acct tags('%s') values(now" ", %" PRId64 ", %" PRId64 ", %" PRId64 ", %" PRId64 @@ -411,13 +1416,34 @@ void monSaveLog(int32_t level, const char *const format, ...) { va_end(argpointer); if (len > max_length) len = max_length; - len += sprintf(sql + len, "', '%s')", tsLocalEp); + len += snprintf(sql + len, SQL_LENGTH, "', '%s')", tsLocalEp); sql[len++] = 0; monDebug("save log, sql: %s", sql); taos_query_a(tsMonitor.conn, sql, monExecSqlCb, "log"); } +void monSaveDnodeLog(int32_t level, const char *const format, ...) { + if (tsMonitor.state != MON_STATE_INITED) return; + + va_list argpointer; + char sql[SQL_LENGTH] = {0}; + int32_t max_length = SQL_LENGTH - 30; + int32_t len = snprintf(sql, (size_t)max_length, "insert into %s.dnode_%d_log values(%" PRId64 ", %d,'", tsMonitorDbName, + dnodeGetDnodeId(), taosGetTimestampUs(), level); + + va_start(argpointer, format); + len += vsnprintf(sql + len, (size_t)(max_length - len), format, argpointer); + va_end(argpointer); + if (len > max_length) len = max_length; + + len += snprintf(sql + len, SQL_LENGTH, "')"); + sql[len++] = 0; + + monDebug("save dnode log, sql: %s", sql); + taos_query_a(tsMonitor.conn, sql, monExecSqlCb, "log"); +} + void monExecuteSQL(char *sql) { if (tsMonitor.state != MON_STATE_INITED) return; @@ -434,3 +1460,19 @@ void monExecuteSQLWithResultCallback(char *sql, MonExecuteSQLCbFP callback, void monDebug("execute sql:%s", sql); taos_query_a(tsMonitor.conn, sql, callback, param); } + +void monIncQueryReqCnt() { + atomic_fetch_add_32(&monQueryReqNum, 1); +} + +void monIncSubmitReqCnt() { + atomic_fetch_add_32(&monSubmitReqNum, 1); +} + +int32_t monFetchQueryReqCnt() { + return atomic_exchange_32(&monQueryReqNum, 0); +} + +int32_t monFetchSubmitReqCnt() { + return atomic_exchange_32(&monSubmitReqNum, 0); +} diff --git a/src/tsdb/src/tsdbMemTable.c b/src/tsdb/src/tsdbMemTable.c index 28993f08c447c2a84a4493e40d74e924ad656c74..6bcffd85f411085f6fc973151fca5d97cf4bd87c 100644 --- a/src/tsdb/src/tsdbMemTable.c +++ b/src/tsdb/src/tsdbMemTable.c @@ -57,7 +57,7 @@ int32_t tsdbInsertData(STsdbRepo *repo, SSubmitMsg *pMsg, SShellSubmitRspMsg *pR STsdbRepo * pRepo = repo; SSubmitMsgIter msgIter = {0}; SSubmitBlk * pBlock = NULL; - int32_t affectedrows = 0; + int32_t affectedrows = 0, numOfRows = 0; if (tsdbScanAndConvertSubmitMsg(pRepo, pMsg) < 0) { if (terrno != TSDB_CODE_TDB_TABLE_RECONFIGURE) { @@ -73,9 +73,13 @@ int32_t tsdbInsertData(STsdbRepo *repo, SSubmitMsg *pMsg, SShellSubmitRspMsg *pR if (tsdbInsertDataToTable(pRepo, pBlock, &affectedrows) < 0) { return -1; } + numOfRows += pBlock->numOfRows; } - if (pRsp != NULL) pRsp->affectedRows = htonl(affectedrows); + if (pRsp != NULL) { + pRsp->affectedRows = htonl(affectedrows); + pRsp->numOfRows = htonl(numOfRows); + } if (tsdbCheckCommit(pRepo) < 0) return -1; return 0; diff --git a/src/vnode/src/vnodeWrite.c b/src/vnode/src/vnodeWrite.c index 35c2ab72dfdf55f66b1095c757fc4f90656c842b..40148fcc6d34196bed1997cb2499a4202a460fe2 100644 --- a/src/vnode/src/vnodeWrite.c +++ b/src/vnode/src/vnodeWrite.c @@ -27,6 +27,10 @@ #define MAX_QUEUED_MSG_NUM 100000 #define MAX_QUEUED_MSG_SIZE 1024*1024*1024 //1GB +static int64_t tsSubmitReqSucNum = 0; +static int64_t tsSubmitRowNum = 0; +static int64_t tsSubmitRowSucNum = 0; + extern void * tsDnodeTmr; static int32_t (*vnodeProcessWriteMsgFp[TSDB_MSG_TYPE_MAX])(SVnodeObj *, void *pCont, SRspRet *); static int32_t vnodeProcessSubmitMsg(SVnodeObj *pVnode, void *pCont, SRspRet *); @@ -163,7 +167,16 @@ static int32_t vnodeProcessSubmitMsg(SVnodeObj *pVnode, void *pCont, SRspRet *pR pRsp = pRet->rsp; } - if (tsdbInsertData(pVnode->tsdb, pCont, pRsp) < 0) code = terrno; + if (tsdbInsertData(pVnode->tsdb, pCont, pRsp) < 0) { + code = terrno; + } else { + if (pRsp != NULL) atomic_fetch_add_64(&tsSubmitReqSucNum, 1); + } + + if (pRsp) { + atomic_fetch_add_64(&tsSubmitRowNum, ntohl(pRsp->numOfRows)); + atomic_fetch_add_64(&tsSubmitRowSucNum, ntohl(pRsp->affectedRows)); + } return code; } @@ -425,3 +438,12 @@ void vnodeWaitWriteCompleted(SVnodeObj *pVnode) { if (extraSleep) taosMsleep(900); } + +SVnodeStatisInfo vnodeGetStatisInfo() { + SVnodeStatisInfo info = {0}; + info.submitReqSucNum = atomic_exchange_64(&tsSubmitReqSucNum, 0); + info.submitRowNum = atomic_exchange_64(&tsSubmitRowNum, 0); + info.submitRowSucNum = atomic_exchange_64(&tsSubmitRowSucNum, 0); + + return info; +} diff --git a/tests/script/unique/cluster/cache.sim b/tests/script/unique/cluster/cache.sim index 740eddfb0d36767631c08a60806ab2e38e6f364a..1b3771353f8ca411db1fc8ea62335c5ecc16bf45 100644 --- a/tests/script/unique/cluster/cache.sim +++ b/tests/script/unique/cluster/cache.sim @@ -41,7 +41,7 @@ sql create dnode $hostname2 sleep 10000 sql show log.tables; -if $rows > 6 then +if $rows > 20 then return -1 endi @@ -50,7 +50,7 @@ print ===>rows $rows print $data00 $data01 $data02 print $data10 $data11 $data12 print $data20 $data21 $data22 -if $rows < 10 then +if $rows < 9 then return -1 endi diff --git a/tests/script/unique/dnode/monitor.sim b/tests/script/unique/dnode/monitor.sim index 0b41a4137ca74046b24e84fb6202279f45eaa578..b1be43ecf58355216266accd308e5e7d41088892 100644 --- a/tests/script/unique/dnode/monitor.sim +++ b/tests/script/unique/dnode/monitor.sim @@ -42,7 +42,7 @@ print dnode2 openVnodes $data2_2 if $data2_1 != 0 then return -1 endi -if $data2_2 != 1 then +if $data2_2 != 2 then return -1 endi @@ -56,7 +56,25 @@ print $data30 print $data40 print $data50 -if $rows > 6 then +print *num of tables $rows + +if $rows > 17 then + return -1 +endi + +sql show log.stables + +print $data00 +print $data10 +print $data20 +print $data30 +print $data40 +print $data50 +print $data60 + +print *num of stables $rows + +if $rows > 7 then return -1 endi diff --git a/tests/script/unique/dnode/monitor_bug.sim b/tests/script/unique/dnode/monitor_bug.sim index 60c6524d9ce70c549cbea2964768888bf0d72fcb..acde8cc3c76297249c71aa0ad307502ce0283391 100644 --- a/tests/script/unique/dnode/monitor_bug.sim +++ b/tests/script/unique/dnode/monitor_bug.sim @@ -19,7 +19,7 @@ sleep 3000 sql show dnodes print dnode1 openVnodes $data2_1 -if $data2_1 > 2 then +if $data2_1 > 4 then return -1 endi @@ -28,20 +28,20 @@ sql create dnode $hostname2 system sh/exec.sh -n dnode2 -s start $x = 0 -show2: +show2: $x = $x + 1 sleep 2000 if $x == 10 then return -1 endi - + sql show dnodes print dnode1 openVnodes $data2_1 print dnode2 openVnodes $data2_2 if $data2_1 != 0 then goto show2 endi -if $data2_2 > 2 then +if $data2_2 > 4 then goto show2 endi @@ -55,7 +55,7 @@ print $data30 print $data40 print $data50 -if $rows > 5 then +if $rows > 14 then return -1 endi @@ -74,4 +74,4 @@ if $rows2 <= $rows1 then endi system sh/exec.sh -n dnode1 -s stop -x SIGINT -system sh/exec.sh -n dnode2 -s stop -x SIGINT \ No newline at end of file +system sh/exec.sh -n dnode2 -s stop -x SIGINT