diff --git a/src/inc/monitor.h b/src/inc/monitor.h index 3744d0b11a59d118cdfcfa706fbd293b8096c9e0..1ac8151672411eb4467378b3d140ec6d1ea4df54 100644 --- a/src/inc/monitor.h +++ b/src/inc/monitor.h @@ -62,6 +62,10 @@ 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(); #ifdef __cplusplus } #endif diff --git a/src/plugins/monitor/src/monMain.c b/src/plugins/monitor/src/monMain.c index 01e4cc599d2ec7f68d6d082b9505e4c6fcd4bc4a..f571765074441ded202777530815a4a6e82160f2 100644 --- a/src/plugins/monitor/src/monMain.c +++ b/src/plugins/monitor/src/monMain.c @@ -77,7 +77,9 @@ typedef struct { } SMonConn; static SMonConn tsMonitor = {0}; -static bool monHasMnodeMaster = false; +static int32_t monQueryReqNum = 0, monSubmitReqNum = 0; +static bool monHasMnodeMaster = false; + static void monSaveSystemInfo(); static void monSaveClusterInfo(); static void monSaveDnodesInfo(); @@ -396,7 +398,8 @@ static int32_t monBuildBandSql(char *sql) { } static int32_t monBuildReqSql(char *sql) { - SStatisInfo info = dnodeGetStatisInfo(); + //SStatisInfo info = dnodeGetStatisInfo(); + SStatisInfo info = {0}; return sprintf(sql, ", %d, %d, %d)", info.httpReqNum, info.queryReqNum, info.submitReqNum); } @@ -429,6 +432,7 @@ 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); } } @@ -685,8 +689,8 @@ static int32_t monBuildReqRateSql(char *sql) { float queryReqRate = info.queryReqNum / interval; float submitReqRate = info.submitReqNum / interval; return sprintf(sql, ", %d, %f, %d, %f, %d, %f", info.httpReqNum, httpReqRate, - info.queryReqNum, queryReqRate, - info.submitReqNum, submitReqRate); + info.queryReqNum - monFetchQueryReqCnt(), queryReqRate, + info.submitReqNum - monFetchSubmitReqCnt(), submitReqRate); } static int32_t monBuildDnodeErrorsSql(char *sql) { @@ -782,6 +786,7 @@ static void monSaveClusterInfo() { 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); } } @@ -811,6 +816,7 @@ static void monSaveDnodesInfo() { 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); } } @@ -893,6 +899,7 @@ static uint32_t monBuildVgroupsInfoSql(char *sql, char *dbName) { 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); } } @@ -968,10 +975,10 @@ static void monSaveSlowQueryInfo() { 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 monExecSqlCb(void *param, TAOS_RES *result, int32_t code) { @@ -979,6 +986,7 @@ static void monExecSqlCb(void *param, TAOS_RES *result, int32_t code) { 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); } @@ -1078,3 +1086,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); +}