diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index 7e52344ba5..989c6614a6 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -438,7 +438,14 @@ void clientSlowQueryMonitorInit(const char* clusterKey); void SlowQueryLog(int64_t rid, bool killed, int32_t code, int32_t cost); void clientSQLReqMonitorInit(const char* clusterKey); -void sqlReqLog(int64_t rid, bool killed, int32_t code); + +enum { + MONITORSQLTYPESELECT = 0, + MONITORSQLTYPEINSERT = 1, + MONITORSQLTYPEDELETE = 2 +}; + +void sqlReqLog(int64_t rid, bool killed, int32_t code, int8_t type); void clientMonitorClose(const char* clusterKey); diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 902c407eb5..77ca10c905 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -98,6 +98,7 @@ static void deregisterRequest(SRequestObj *pRequest) { pRequest->metric.planCostUs, pRequest->metric.execCostUs); atomic_add_fetch_64((int64_t *)&pActivity->insertElapsedTime, duration); reqType = SLOW_LOG_TYPE_INSERT; + sqlReqLog(pTscObj->id, pRequest->killed, pRequest->code, MONITORSQLTYPEINSERT); } else if (QUERY_NODE_SELECT_STMT == pRequest->stmtType) { tscDebug("query duration %" PRId64 "us: parseCost:%" PRId64 "us, ctgCost:%" PRId64 "us, analyseCost:%" PRId64 "us, planCost:%" PRId64 "us, exec:%" PRId64 "us", @@ -105,8 +106,10 @@ static void deregisterRequest(SRequestObj *pRequest) { pRequest->metric.planCostUs, pRequest->metric.execCostUs); atomic_add_fetch_64((int64_t *)&pActivity->queryElapsedTime, duration); - sqlReqLog(pTscObj->id, pRequest->killed, pRequest->code); reqType = SLOW_LOG_TYPE_QUERY; + sqlReqLog(pTscObj->id, pRequest->killed, pRequest->code, MONITORSQLTYPESELECT); + } else if (QUERY_NODE_DELETE_STMT == pRequest->stmtType) { + sqlReqLog(pTscObj->id, pRequest->killed, pRequest->code, MONITORSQLTYPEDELETE); } } diff --git a/source/client/src/clientSqlMonitor.c b/source/client/src/clientSqlMonitor.c index 89b91646ff..572af7ff55 100644 --- a/source/client/src/clientSqlMonitor.c +++ b/source/client/src/clientSqlMonitor.c @@ -32,12 +32,24 @@ void clientSQLReqMonitorInit(const char* clusterKey) { createClusterCounter(clusterKey, selectMonitorName, selectMonitorHelp, selectMonitorLabelCount, selectMonitorLabels); } -void clientSQLReqLog(const char* clusterKey, const char* user, SQL_RESULT_CODE result) { - const char* selectMonitorLabelValues[] = {defaultClusterID, "select", user, resultStr(result)}; +void clientSQLReqLog(const char* clusterKey, const char* user, SQL_RESULT_CODE result, int8_t type) { + const char* typeStr; + switch (type) { + case MONITORSQLTYPEDELETE: + typeStr = "delete"; + break; + case MONITORSQLTYPEINSERT: + typeStr = "insert"; + break; + default: + typeStr = "select"; + break; + } + const char* selectMonitorLabelValues[] = {defaultClusterID, typeStr, user, resultStr(result)}; taosClusterCounterInc(clusterKey, selectMonitorName, selectMonitorLabelValues); } -void sqlReqLog(int64_t rid, bool killed, int32_t code) { +void sqlReqLog(int64_t rid, bool killed, int32_t code, int8_t type) { if (!tsEnableMonitor) return; SQL_RESULT_CODE result = SQL_RESULT_SUCCESS; if (TSDB_CODE_SUCCESS != code) { @@ -53,7 +65,7 @@ void sqlReqLog(int64_t rid, bool killed, int32_t code) { if (pTscObj->pAppInfo == NULL) { tscLog("sqlReqLog, not found pAppInfo"); } else { - clientSQLReqLog(pTscObj->pAppInfo->instKey, pTscObj->user, result); + clientSQLReqLog(pTscObj->pAppInfo->instKey, pTscObj->user, result, type); } releaseTscObj(rid); } else {