TDengine/source/client/src/clientMonitorSql.c

73 lines
2.4 KiB
C
Raw Normal View History

2023-11-02 10:44:18 +00:00
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "clientInt.h"
#include "clientMonitor.h"
#include "clientLog.h"
2024-02-02 06:54:31 +00:00
#include "tglobal.h"
2023-11-02 10:44:18 +00:00
2024-02-02 06:16:28 +00:00
const char* selectMonitorName = "taos_sql_req:count";
2024-02-02 05:39:31 +00:00
const char* selectMonitorHelp = "count for select sql";
const int selectMonitorLabelCount = 4;
const char* selectMonitorLabels[] = {"cluster_id", "sql_type", "username", "result"};
2024-06-19 10:54:26 +00:00
void monitorClientSQLReqInit(int64_t clusterId) {
monitorCreateClient(clusterId);
monitorCreateClientCounter(clusterId, selectMonitorName, selectMonitorHelp, selectMonitorLabelCount, selectMonitorLabels);
2023-11-02 10:44:18 +00:00
}
2024-06-19 10:54:26 +00:00
void clientSQLReqLog(int64_t clusterId, const char* user, SQL_RESULT_CODE result, int8_t type) {
2024-02-19 06:27:54 +00:00
const char* typeStr;
switch (type) {
case MONITORSQLTYPEDELETE:
typeStr = "delete";
break;
case MONITORSQLTYPEINSERT:
typeStr = "insert";
break;
default:
typeStr = "select";
break;
}
2024-06-19 10:54:26 +00:00
char clusterIdStr[32] = {0};
if (snprintf(clusterIdStr, sizeof(clusterIdStr), "%" PRId64, clusterId) < 0){
uError("failed to generate clusterId:%" PRId64, clusterId);
}
const char* selectMonitorLabelValues[] = {clusterIdStr, typeStr, user, monitorResultStr(result)};
monitorCounterInc(clusterId, selectMonitorName, selectMonitorLabelValues);
2023-11-02 10:44:18 +00:00
}
2024-02-19 06:27:54 +00:00
void sqlReqLog(int64_t rid, bool killed, int32_t code, int8_t type) {
2024-02-02 05:39:31 +00:00
SQL_RESULT_CODE result = SQL_RESULT_SUCCESS;
if (TSDB_CODE_SUCCESS != code) {
result = SQL_RESULT_FAILED;
}
// to do Distinguish active Kill events
// else if (killed) {
// result = SQL_RESULT_CANCEL;
// }
2023-12-14 03:41:47 +00:00
STscObj* pTscObj = acquireTscObj(rid);
2023-11-02 10:44:18 +00:00
if (pTscObj != NULL) {
2024-02-02 05:39:31 +00:00
if (pTscObj->pAppInfo == NULL) {
2024-02-02 07:25:35 +00:00
tscLog("sqlReqLog, not found pAppInfo");
2024-02-05 07:18:09 +00:00
} else {
2024-06-19 10:54:26 +00:00
clientSQLReqLog(pTscObj->pAppInfo->clusterId, pTscObj->user, result, type);
2023-11-02 10:44:18 +00:00
}
(void)releaseTscObj(rid);
2023-11-02 10:44:18 +00:00
} else {
2024-02-02 07:25:35 +00:00
tscLog("sqlReqLog, not found rid");
2023-11-02 10:44:18 +00:00
}
}