From 1c3021cd43b024f597a117da59651120453ce3b8 Mon Sep 17 00:00:00 2001 From: slguan Date: Thu, 23 Apr 2020 21:55:15 +0800 Subject: [PATCH] [TD-91] refactor monitor module --- src/dnode/inc/dnodeLog.h | 4 -- src/inc/monitor.h | 32 +++++++++- src/inc/taosmsg.h | 1 - src/mnode/inc/mgmtLog.h | 13 ++-- src/plugins/http/inc/httpLog.h | 5 -- src/plugins/monitor/inc/monitorSystem.h | 59 ------------------- .../src/{monitorSystem.c => monitorMain.c} | 11 +++- src/vnode/inc/vnodeLog.h | 4 -- src/vnode/src/vnodeMain.c | 3 + 9 files changed, 48 insertions(+), 84 deletions(-) delete mode 100644 src/plugins/monitor/inc/monitorSystem.h rename src/plugins/monitor/src/{monitorSystem.c => monitorMain.c} (98%) diff --git a/src/dnode/inc/dnodeLog.h b/src/dnode/inc/dnodeLog.h index 380e93dd7b..18a5874e44 100644 --- a/src/dnode/inc/dnodeLog.h +++ b/src/dnode/inc/dnodeLog.h @@ -39,10 +39,6 @@ extern int32_t ddebugFlag; #define dPrint(...) \ { taosPrintLog("DND ", 255, __VA_ARGS__); } -#define dLError(...) taosLogError(__VA_ARGS__) dError(__VA_ARGS__) -#define dLWarn(...) taosLogWarn(__VA_ARGS__) dWarn(__VA_ARGS__) -#define dLPrint(...) taosLogPrint(__VA_ARGS__) dPrint(__VA_ARGS__) - #ifdef __cplusplus } #endif diff --git a/src/inc/monitor.h b/src/inc/monitor.h index bb63bf63a4..b1229cca6b 100644 --- a/src/inc/monitor.h +++ b/src/inc/monitor.h @@ -22,10 +22,38 @@ extern "C" { #include +typedef struct { + char * acctId; + int64_t currentPointsPerSecond; + int64_t maxPointsPerSecond; + int64_t totalTimeSeries; + int64_t maxTimeSeries; + int64_t totalStorage; + int64_t maxStorage; + int64_t totalQueryTime; + int64_t maxQueryTime; + int64_t totalInbound; + int64_t maxInbound; + int64_t totalOutbound; + int64_t maxOutbound; + int64_t totalDbs; + int64_t maxDbs; + int64_t totalUsers; + int64_t maxUsers; + int64_t totalStreams; + int64_t maxStreams; + int64_t totalConns; + int64_t maxConns; + int8_t accessState; +} SAcctMonitorObj; + int32_t monitorInitSystem(); int32_t monitorStartSystem(); -void monitorStopSystem(); -void monitorCleanUpSystem(); +void monitorStopSystem(); +void monitorCleanUpSystem(); +void monitorSaveAcctLog(SAcctMonitorObj *pMonObj); +void monitorSaveLog(int32_t level, const char *const format, ...); +void monitorExecuteSQL(char *sql); #ifdef __cplusplus } diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index 7d9c343a85..9f1d8033b1 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -509,7 +509,6 @@ typedef struct { int64_t pointsWritten; uint8_t status; uint8_t role; - uint8_t accessState; uint8_t replica; uint8_t reserved[5]; } SVnodeLoad; diff --git a/src/mnode/inc/mgmtLog.h b/src/mnode/inc/mgmtLog.h index fb4bb39828..a99fa22593 100644 --- a/src/mnode/inc/mgmtLog.h +++ b/src/mnode/inc/mgmtLog.h @@ -21,6 +21,7 @@ extern "C" { #endif #include "tlog.h" +#include "monitor.h" extern int32_t mdebugFlag; extern int32_t sdbDebugFlag; @@ -41,9 +42,9 @@ extern int32_t sdbDebugFlag; #define mPrint(...) \ { taosPrintLog("MND ", 255, __VA_ARGS__); } -#define mLError(...) mError(__VA_ARGS__) -#define mLWarn(...) mWarn(__VA_ARGS__) -#define mLPrint(...) mPrint(__VA_ARGS__) +#define mLError(...) monitorSaveLog(2, __VA_ARGS__); mError(__VA_ARGS__) +#define mLWarn(...) monitorSaveLog(1, __VA_ARGS__); mWarn(__VA_ARGS__) +#define mLPrint(...) monitorSaveLog(0, __VA_ARGS__); mPrint(__VA_ARGS__) #define sdbError(...) \ if (sdbDebugFlag & DEBUG_ERROR) { \ @@ -60,9 +61,9 @@ extern int32_t sdbDebugFlag; #define sdbPrint(...) \ { taosPrintLog("MND-SDB ", 255, __VA_ARGS__); } -#define sdbLError(...) sdbError(__VA_ARGS__) -#define sdbLWarn(...) sdbWarn(__VA_ARGS__) -#define sdbLPrint(...) sdbPrint(__VA_ARGS__) +#define sdbLError(...) monitorSaveLog(2, __VA_ARGS__); sdbError(__VA_ARGS__) +#define sdbLWarn(...) monitorSaveLog(1, __VA_ARGS__); sdbWarn(__VA_ARGS__) +#define sdbLPrint(...) monitorSaveLog(0, __VA_ARGS__); sdbPrint(__VA_ARGS__) #ifdef __cplusplus } diff --git a/src/plugins/http/inc/httpLog.h b/src/plugins/http/inc/httpLog.h index 1723c30ab9..19fa46bd23 100644 --- a/src/plugins/http/inc/httpLog.h +++ b/src/plugins/http/inc/httpLog.h @@ -39,9 +39,4 @@ extern int32_t httpDebugFlag; #define httpPrint(...) \ { taosPrintLog("HTP ", 255, __VA_ARGS__); } -#define httpLError(...) taosLogError(__VA_ARGS__) httpError(__VA_ARGS__) -#define httpLWarn(...) taosLogWarn(__VA_ARGS__) httpWarn(__VA_ARGS__) -#define httpLPrint(...) taosLogPrint(__VA_ARGS__) httpPrint(__VA_ARGS__) - - #endif diff --git a/src/plugins/monitor/inc/monitorSystem.h b/src/plugins/monitor/inc/monitorSystem.h deleted file mode 100644 index 91aa4d2ad6..0000000000 --- a/src/plugins/monitor/inc/monitorSystem.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef TDENGINE_MONITOR_SYSTEM_H -#define TDENGINE_MONITOR_SYSTEM_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -typedef struct { - char * acctId; - int64_t currentPointsPerSecond; - int64_t maxPointsPerSecond; - int64_t totalTimeSeries; - int64_t maxTimeSeries; - int64_t totalStorage; - int64_t maxStorage; - int64_t totalQueryTime; - int64_t maxQueryTime; - int64_t totalInbound; - int64_t maxInbound; - int64_t totalOutbound; - int64_t maxOutbound; - int64_t totalDbs; - int64_t maxDbs; - int64_t totalUsers; - int64_t maxUsers; - int64_t totalStreams; - int64_t maxStreams; - int64_t totalConns; - int64_t maxConns; - int8_t accessState; -} SAcctMonitorObj; - -void monitorSaveAcctLog(SAcctMonitorObj *pMonObj); -void monitorSaveLog(int32_t level, const char *const format, ...); -void monitorExecuteSQL(char *sql); - -#ifdef __cplusplus -} -#endif - -#endif \ No newline at end of file diff --git a/src/plugins/monitor/src/monitorSystem.c b/src/plugins/monitor/src/monitorMain.c similarity index 98% rename from src/plugins/monitor/src/monitorSystem.c rename to src/plugins/monitor/src/monitorMain.c index a2c73fbb58..dade813d9c 100644 --- a/src/plugins/monitor/src/monitorSystem.c +++ b/src/plugins/monitor/src/monitorMain.c @@ -25,7 +25,7 @@ #include "tscUtil.h" #include "tsclient.h" #include "dnode.h" -#include "monitorSystem.h" +#include "monitor.h" #define monitorError(...) \ if (monitorDebugFlag & DEBUG_ERROR) { \ @@ -228,7 +228,6 @@ static void monitorInitDatabaseCb(void *param, TAOS_RES *result, int32_t code) { void monitorStopSystem() { monitorPrint("monitor module is stopped"); tsMonitorConn.state = MONITOR_STATE_STOPPED; - // taosLogFp = NULL; if (tsMonitorConn.initTimer != NULL) { taosTmrStopA(&(tsMonitorConn.initTimer)); } @@ -399,6 +398,8 @@ void monitorSaveAcctLog(SAcctMonitorObj *pMon) { } void monitorSaveLog(int32_t level, const char *const format, ...) { + if (tsMonitorConn.state != MONITOR_STATE_INITIALIZED) return; + va_list argpointer; char sql[SQL_LENGTH] = {0}; int32_t max_length = SQL_LENGTH - 30; @@ -421,6 +422,10 @@ void monitorSaveLog(int32_t level, const char *const format, ...) { } void monitorExecuteSQL(char *sql) { + if (tsMonitorConn.state != MONITOR_STATE_INITIALIZED) return; + monitorTrace("monitor:%p, execute sql: %s", tsMonitorConn.conn, sql); - taos_query_a(tsMonitorConn.conn, sql, NULL, NULL); + + // bug while insert binary + // taos_query_a(tsMonitorConn.conn, sql, NULL, NULL); } diff --git a/src/vnode/inc/vnodeLog.h b/src/vnode/inc/vnodeLog.h index 5650321fdb..450220e17f 100644 --- a/src/vnode/inc/vnodeLog.h +++ b/src/vnode/inc/vnodeLog.h @@ -39,10 +39,6 @@ extern int32_t ddebugFlag; #define dPrint(...) \ { taosPrintLog("DND ", 255, __VA_ARGS__); } -#define dLError(...) taosLogError(__VA_ARGS__) dError(__VA_ARGS__) -#define dLWarn(...) taosLogWarn(__VA_ARGS__) dWarn(__VA_ARGS__) -#define dLPrint(...) taosLogPrint(__VA_ARGS__) dPrint(__VA_ARGS__) - #ifdef __cplusplus } #endif diff --git a/src/vnode/src/vnodeMain.c b/src/vnode/src/vnodeMain.c index 6936dc0345..26791ae77c 100644 --- a/src/vnode/src/vnodeMain.c +++ b/src/vnode/src/vnodeMain.c @@ -332,6 +332,9 @@ static void vnodeBuildVloadMsg(char *pNode, void * param) { SVnodeLoad *pLoad = &pStatus->load[pStatus->openVnodes++]; pLoad->vgId = htonl(pVnode->vgId); + pLoad->totalStorage = htobe64(pLoad->totalStorage); + pLoad->compStorage = htobe64(pLoad->compStorage); + pLoad->pointsWritten = htobe64(pLoad->pointsWritten); pLoad->status = pVnode->status; pLoad->role = pVnode->role; pLoad->replica = pVnode->syncCfg.replica; -- GitLab